package com.metasoft.flex.util {
	
	import _2005.extended.metadata.tva.AgeRangeType;
	import _2005.extended.metadata.tva.BiographicInformationType;
	import _2005.extended.metadata.tva.ContentPropertiesType;
	import _2005.extended.metadata.tva.DescriptorType;
	import _2005.extended.metadata.tva.ExtendedContentDescriptionType;
	import _2005.extended.metadata.tva.ExtendedTVAMainType;
	import _2005.extended.metadata.tva.ExtendedUserDescriptionType;
	import _2005.extended.metadata.tva.FilePropertiesType;
	import _2005.extended.metadata.tva.LanguageType;
	import _2005.extended.metadata.tva.ObjectDescriptionType;
	import _2005.extended.metadata.tva.PackageTableType;
	import _2005.extended.metadata.tva.PackageType;
	import _2005.extended.metadata.tva.TVAMainDocument;
	import _2005.extended.metadata.tva.TargetingInformationTableType;
	import _2005.extended.metadata.tva.TargetingInformationType;
	import _2005.extended.metadata.tva.UserInformationTableType;
	import _2005.extended.metadata.tva.UserInformationType;
	import _2005.metadata.tva.AuthorType;
	import _2005.metadata.tva.AwardType;
	import _2005.metadata.tva.AwardsListItemType;
	import _2005.metadata.tva.AwardsListType;
	import _2005.metadata.tva.BaseMemberOfType;
	import _2005.metadata.tva.BasicContentDescriptionType;
	import _2005.metadata.tva.BasicSegmentDescriptionType;
	import _2005.metadata.tva.CRIDRefType;
	import _2005.metadata.tva.ControlledTermType;
	import _2005.metadata.tva.CopyrightType;
	import _2005.metadata.tva.CostType;
	import _2005.metadata.tva.CreditsItemType;
	import _2005.metadata.tva.CreditsListType;
	import _2005.metadata.tva.GenreType;
	import _2005.metadata.tva.KeywordType;
	import _2005.metadata.tva.PreviewType;
	import _2005.metadata.tva.ProgramDescriptionType;
	import _2005.metadata.tva.ProgramInformationTableType;
	import _2005.metadata.tva.ProgramInformationType;
	import _2005.metadata.tva.RelatedMaterialType;
	import _2005.metadata.tva.SegmentGroupInformationType;
	import _2005.metadata.tva.SegmentGroupListType;
	import _2005.metadata.tva.SegmentInformationTableType;
	import _2005.metadata.tva.SegmentInformationType;
	import _2005.metadata.tva.SegmentListType;
	import _2005.metadata.tva.SegmentsType;
	import _2005.metadata.tva.SynopsisLengthType;
	import _2005.metadata.tva.SynopsisType;
	import _2005.metadata.tva.TVAIDType;
	import _2005.metadata.tva.TVAMediaRelIncrTimePointType;
	import _2005.metadata.tva.TVAMediaTimeType;
	import _2005.metadata.tva.TermNameType;
	import _2005.metadata.tva.ThumbnailType;
	import _2005.metadata.tva.Type;
	import _2005.metadata.tva.UserDescriptionType;
	import _2005.mpeg7.tva.ClassificationPreferencesType;
	import _2005.mpeg7.tva.ControlledTermUseType;
	import _2005.mpeg7.tva.CreationPreferencesType;
	import _2005.mpeg7.tva.Creator;
	import _2005.mpeg7.tva.CreatorType;
	import _2005.mpeg7.tva.FilteringAndSearchPreferencesType;
	import _2005.mpeg7.tva.Genre;
	import _2005.mpeg7.tva.Keyword;
	import _2005.mpeg7.tva.MediaIncrDurationType;
	import _2005.mpeg7.tva.MediaLocatorType;
	import _2005.mpeg7.tva.Name;
	import _2005.mpeg7.tva.NameComponentType;
	import _2005.mpeg7.tva.NameType;
	import _2005.mpeg7.tva.ParentalGuidanceType;
	import _2005.mpeg7.tva.PersonNameType;
	import _2005.mpeg7.tva.TermUseType;
	import _2005.mpeg7.tva.TextualType;
	import _2005.mpeg7.tva.TimeType;
	import _2005.mpeg7.tva.TitleType;
	import _2005.mpeg7.tva.UniqueIDType;
	import _2005.mpeg7.tva.UsageHistoryType;
	import _2005.mpeg7.tva.UserActionHistoryType;
	import _2005.mpeg7.tva.UserActionListType;
	import _2005.mpeg7.tva.UserActionType;
	import _2005.mpeg7.tva.UserActionType_ActionTime;
	import _2005.mpeg7.tva.UserIdentifierType;
	import _2005.mpeg7.tva.UserPreferencesType;
	import _2005.profile.tva.Modification;
	import _2005.profile.tva.ModifyDocument;
	import _2005.profile.tva.ModifyType;
	import _2005.profile.tva.NewData;
	import _2005.profile.tva.QueryDocument;
	import _2005.profile.tva.QueryItemType;
	import _2005.profile.tva.QueryType;
	import _2005.profile.tva.ResourceIDType;
	import _2005.profile.tva.SelectType;
	import _2005.transport.tva.BinaryPredicateType;
	import _2005.transport.tva.DeleteDataDocument;
	import _2005.transport.tva.DeleteDataType;
	import _2005.transport.tva.DeleteTableType_Enum;
	import _2005.transport.tva.GetDataDocument;
	import _2005.transport.tva.GetDataType;
	import _2005.transport.tva.PredicateBagType;
	import _2005.transport.tva.QueryConstraintsInfo;
	import _2005.transport.tva.RequestedTablesType;
	import _2005.transport.tva.TableType;
	import _2005.transport.tva.UploadPersonalDataDocument;
	import _2005.transport.tva.UploadPersonalDataType;
	
	import com.metasoft.flex.AssetItem;
	import com.metasoft.flex.MetasoftULC;
	import com.metasoft.flex.ProgramItem;
	import com.metasoft.flex.dto.CreditItemInfo;
	import com.metasoft.flex.dto.GroupInfoDTO;
	import com.metasoft.flex.dto.ProfileInfo;
	import com.metasoft.flex.dto.SegmentInfoDTO;
	import com.metasoft.flex.dto.SegmentItem;
	import com.metasoft.flex.dto.ServiceInfoDTO;
	import com.metasoft.flex.dto.TargetingInfoDTO;
	import com.metasoft.flex.server.MetasoftServer;
	import com.metasoft.flex.service.MetasoftService;
	
	import flash.net.SharedObject;
	import flash.xml.XMLNode;
	
	import mx.collections.ArrayCollection;
	import mx.formatters.DateFormatter;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	import samples.flexstore.Product;
	
	public class MetasoftHelper {
		
		public static function getProgramsFromProxy(get_Data_Result:Object):Array {

			var so:SharedObject = SharedObject.getLocal(MetasoftULC.LoggedInUser);
			var j:int = 0;
			var programItems:Array = new Array();
			var prgItem:Product;
			if (get_Data_Result == null) return programItems;
			var tvaMain:Object = get_Data_Result.TVAMain;
            if (tvaMain == null) return programItems;
            var programDescription:Object = tvaMain.programDescription;
            var programInformationTable:Object = programDescription.programInformationTable;
            var programInformationArray:Array = programInformationTable.programInformationArray;
			if (programInformationArray != null && programInformationArray.length > 0) {

	            var pi:Object = new Object();
	            for each(pi in programInformationArray) {
	
					var basicDescription:Object = pi.basicDescription as Object;
					if (basicDescription == null) {
						continue;
					}
					prgItem = new Product();
					if (pi.programId != null) {
						prgItem.id = String(pi.programId);
					}
					if (basicDescription.titleArray[0] != null) {
						prgItem.title = basicDescription.titleArray[0].stringValue;
					}
					if (basicDescription.synopsisArray[0] != null) {
						prgItem.synopsis = basicDescription.synopsisArray[0].stringValue;
					}
					if (basicDescription.thumbnail != null) {
						prgItem.thumbnail = basicDescription.thumbnail.stringValue;
					}
					if (basicDescription.preview != null) {
						//prgItem.preview = MetasoftUtils.getImageURI(basicDescription.preview.stringValue);
						prgItem.preview = basicDescription.preview.stringValue;
					}
					if (basicDescription.copyright != null) {
						prgItem.copyRight = basicDescription.copyright.stringValue;
					}
					
					if (basicDescription.author != null) {
						prgItem.author = basicDescription.author.stringValue;
					}

					if (basicDescription.keywordArray != null &&
						basicDescription.keywordArray.length > 0) {
						
						prgItem.keyword = basicDescription.keywordArray[0].stringValue;
						prgItem.tags = new Array();
						for(j = 0; j < basicDescription.keywordArray.length; j++) {

							if (basicDescription.keywordArray[j] != null) {
								prgItem.tags.push(basicDescription.keywordArray[j].stringValue);
							}
						}
					}
					if (basicDescription.cost != null)	{
						prgItem.price = MetasoftUtils.getCost(basicDescription.cost.stringValue);
					} else { 
						prgItem.price = "0.0";
					}
					var thumbnailStreamArray:Array = null;
					if (basicDescription.mediaTitleArray != null && 
					 	basicDescription.mediaTitleArray.length > 0 ) {

						thumbnailStreamArray = new Array();
						for (j = 0; j < basicDescription.mediaTitleArray.length; j++) {

							if (basicDescription.mediaTitleArray[j] != null) {
						 		thumbnailStreamArray.push(basicDescription.mediaTitleArray[j].stringValue);
						 	}
					 	}
					 	prgItem.thumbnailStream = thumbnailStreamArray;
					} else if (basicDescription.thumbnail != null) {

						thumbnailStreamArray = new Array();
						thumbnailStreamArray.push(basicDescription.thumbnail.stringValue);
					}
					if (basicDescription.genreArray != null && 
						basicDescription.genreArray.length > 0) {

						var genreArray:Array 	= basicDescription.genreArray;
						prgItem.content    		= getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_Content, prgItem);
						prgItem.contentType    	= getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_ContentType, prgItem);
						prgItem.intentions 		= getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_Intention, prgItem);
						prgItem.atmosphere 		= getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_Atmosphere, prgItem);
						prgItem.format     		= getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_Format, prgItem);
						prgItem.intendedAudience= getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_IntendedAudience, prgItem);
						prgItem.mediaType  		= getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_MediaType, prgItem);
						getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_OriginationType, prgItem);
						getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_ContentAlertType, prgItem);
						
						
				    }
					var temp:Array = new Array();
//					for each (var img:Object in prgItem.thumbnailStream) {
////						if (img != null && img.titleImage != null)
////							temp.push((String(img.titleImage.mediaUri)));
//					}
//					if (temp.length > 0) {
//						prgItem.thumbnailStream = temp;
//					}
//					temp = new Array();
					if (basicDescription.relatedMaterialArray != null && 
						basicDescription.relatedMaterialArray is Array && 
						basicDescription.relatedMaterialArray.length > 0) {
						temp = basicDescription.relatedMaterialArray;
					}
					prgItem.relatedMaterial = new Array();
					var i:int = 0;
					var officialURI:String = "";
					var promoInfo:String = "";
					for each (var rm:Object in temp) {

						var icon:String = "";
						var link:String = "";
						if (rm != null && 
							rm.promotionalMediaArray != null && 
							rm.promotionalMediaArray.titleVideo != null) {

							prgItem.trailers[i] = rm.promotionalMediaArray.titleVideo.mediaUri;
							icon = rm.promotionalMediaArray.titleVideo.mediaUri;
						} else {
							icon = prgItem.thumbnail;
						}
						if (rm != null && rm.mediaLocator != null && rm.mediaLocator.mediaUri != null) {
							link = rm.mediaLocator.mediaUri;
						}
						if (rm != null && rm.promotionalTextArray != null && rm.promotionalTextArray.length != 0) {
							
							if(rm.promotionalTextArray[0] !=null)
								promoInfo = rm.promotionalTextArray[0].stringValue;
						}
						//link = MetasoftUtils.getURI(link);
						link = MetasoftUtils.getResourceURI(link, so.data.userId);
						prgItem.relatedMaterial[i] = [icon,link];
						officialURI = link;
						i++;
					}
					
					if(promoInfo !=null && promoInfo.length !=0) {
						prgItem.promoInfo = promoInfo;
					}
					
					if(officialURI) {
						prgItem.officialURI = officialURI;
					}
					
					if (basicDescription.creditsList != null) {
						prgItem.creditItems = getCreditItemsFromProxy(basicDescription.creditsList, prgItem);
					}
					//AwardList
					if (basicDescription.awardsList != null) {
						getAwardItemsFromProxy(basicDescription.awardsList, prgItem);
					}
					
					// for parental guidance
					if (basicDescription.parentalGuidanceArray != null && 
						basicDescription.parentalGuidanceArray.length > 0) {
							
						prgItem.parentalGuidanceArray = getParentalGuidanceFromProxy(basicDescription.parentalGuidanceArray);
						if (basicDescription.parentalGuidanceArray[0] != null && 
							basicDescription.parentalGuidanceArray[0] != null && 
							basicDescription.parentalGuidanceArray[0].parentalRating !=null) { 
						
							prgItem.parentalGuidance = basicDescription.parentalGuidanceArray[0].parentalRating.href;
						}
					}
					//for ReleaseDate
					if (basicDescription.releaseInformationArray != null && 
						basicDescription.releaseInformationArray.length > 0 &&
						basicDescription.releaseInformationArray[0].releaseDate != null) {
						prgItem.releaseDate =  basicDescription.releaseInformationArray[0].releaseDate.dayAndYear;
					}
					programItems.push(prgItem);
	            }
	  		}
			return programItems;
		}
		
		public static function getProgramsFromGroupInfo(get_Data_Result:Object, groupId:String):Array {

			var so:SharedObject = SharedObject.getLocal(MetasoftULC.LoggedInUser);
			var j:int = 0;
			var programItems:Array = new Array();
			var prgItem:Product;
			if (get_Data_Result == null) return programItems;
			var tvaMain:Object = get_Data_Result.TVAMain;
            if (tvaMain == null) return programItems;
            var programDescription:Object = tvaMain.programDescription;
            var programInformationTable:Object = programDescription.programInformationTable;
            var programInformationArray:Array = programInformationTable.programInformationArray;
			if (programInformationArray != null && programInformationArray.length > 0) {

	            var pi:Object = new Object();
	            for each(pi in programInformationArray) {
	
					var basicDescription:Object = pi.basicDescription as Object;
					if (basicDescription == null) {
						continue;
					}
					prgItem = new Product();
					if (pi.programId != null) {
						prgItem.id = String(pi.programId);
					}
					
					//MemberOf
					if(groupId !=null && groupId!="" &&
						pi.memberOfArray != null && 
						pi.memberOfArray.length > 0) {
							
						prgItem.memberOfIndex = getMemeberOfIndex(pi.memberOfArray, groupId);
					}
					if (basicDescription.titleArray[0] != null) {
						prgItem.title = basicDescription.titleArray[0].stringValue;
					}
					if (basicDescription.synopsisArray[0] != null) {
						prgItem.synopsis = basicDescription.synopsisArray[0].stringValue;
					}
					if (basicDescription.thumbnail != null) {
						prgItem.thumbnail = basicDescription.thumbnail.stringValue;
					}
					if (basicDescription.preview != null) {
						//prgItem.preview = MetasoftUtils.getImageURI(basicDescription.preview.stringValue);
						prgItem.preview = basicDescription.preview.stringValue;
					}
					if (basicDescription.copyright != null) {
						prgItem.copyRight = basicDescription.copyright.stringValue;
					}
					
					if (basicDescription.author != null) {
						prgItem.author = basicDescription.author.stringValue;
					}

					if (basicDescription.keywordArray != null &&
						basicDescription.keywordArray.length > 0) {
						
						prgItem.keyword = basicDescription.keywordArray[0].stringValue;
						prgItem.tags = new Array();
						for(j = 0; j < basicDescription.keywordArray.length; j++) {

							if (basicDescription.keywordArray[j] != null) {
								prgItem.tags.push(basicDescription.keywordArray[j].stringValue);
							}
						}
					}
					if (basicDescription.cost != null)	{
						prgItem.price = MetasoftUtils.getCost(basicDescription.cost.stringValue);
					} else { 
						prgItem.price = "0.0";
					}
					var thumbnailStreamArray:Array = null;
					if (basicDescription.mediaTitleArray != null && 
					 	basicDescription.mediaTitleArray.length > 0 ) {

						thumbnailStreamArray = new Array();
						for (j = 0; j < basicDescription.mediaTitleArray.length; j++) {

							if (basicDescription.mediaTitleArray[j] != null) {
						 		thumbnailStreamArray.push(basicDescription.mediaTitleArray[j].stringValue);
						 	}
					 	}
					 	prgItem.thumbnailStream = thumbnailStreamArray;
					} else if (basicDescription.thumbnail != null) {

						thumbnailStreamArray = new Array();
						thumbnailStreamArray.push(basicDescription.thumbnail.stringValue);
					}
					if (basicDescription.genreArray != null && 
						basicDescription.genreArray.length > 0) {

						var genreArray:Array 	= basicDescription.genreArray;
						prgItem.content    		= getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_Content, prgItem);
						prgItem.contentType    	= getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_ContentType, prgItem);
						prgItem.intentions 		= getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_Intention, prgItem);
						prgItem.atmosphere 		= getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_Atmosphere, prgItem);
						prgItem.format     		= getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_Format, prgItem);
						prgItem.intendedAudience= getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_IntendedAudience, prgItem);
						prgItem.mediaType  		= getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_MediaType, prgItem);
						getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_OriginationType, prgItem);
						getGenreFromObjectByProduct(genreArray, MetasoftULC.CS_ContentAlertType, prgItem);
						
						
				    }
					var temp:Array = new Array();
//					for each (var img:Object in prgItem.thumbnailStream) {
////						if (img != null && img.titleImage != null)
////							temp.push((String(img.titleImage.mediaUri)));
//					}
//					if (temp.length > 0) {
//						prgItem.thumbnailStream = temp;
//					}
//					temp = new Array();
					if (basicDescription.relatedMaterialArray != null && 
						basicDescription.relatedMaterialArray is Array && 
						basicDescription.relatedMaterialArray.length > 0) {
						temp = basicDescription.relatedMaterialArray;
					}
					prgItem.relatedMaterial = new Array();
					var i:int = 0;
					var officialURI:String = "";
					var promoInfo:String = "";
					for each (var rm:Object in temp) {

						var icon:String = "";
						var link:String = "";
						if (rm != null && 
							rm.promotionalMediaArray != null && 
							rm.promotionalMediaArray.titleVideo != null) {

							prgItem.trailers[i] = rm.promotionalMediaArray.titleVideo.mediaUri;
							icon = rm.promotionalMediaArray.titleVideo.mediaUri;
						} else {
							icon = prgItem.thumbnail;
						}
						if (rm != null && rm.mediaLocator != null && rm.mediaLocator.mediaUri != null) {
							link = rm.mediaLocator.mediaUri;
						}
						if (rm != null && rm.promotionalTextArray != null && rm.promotionalTextArray.length != 0) {
							
							if(rm.promotionalTextArray[0] !=null)
								promoInfo = rm.promotionalTextArray[0].stringValue;
						}
						//link = MetasoftUtils.getURI(link);
						link = MetasoftUtils.getResourceURI(link, so.data.userId);
						prgItem.relatedMaterial[i] = [icon,link];
						officialURI = link;
						i++;
					}
					
					if(promoInfo !=null && promoInfo.length !=0) {
						prgItem.promoInfo = promoInfo;
					}
					
					if(officialURI) {
						prgItem.officialURI = officialURI;
					}
					
					if (basicDescription.creditsList != null) {
						prgItem.creditItems = getCreditItemsFromProxy(basicDescription.creditsList, prgItem);
					}
					//AwardList
					if (basicDescription.awardsList != null) {
						getAwardItemsFromProxy(basicDescription.awardsList, prgItem);
					}
					
					// for parental guidance
					if (basicDescription.parentalGuidanceArray != null && 
						basicDescription.parentalGuidanceArray.length > 0) {
							
						prgItem.parentalGuidanceArray = getParentalGuidanceFromProxy(basicDescription.parentalGuidanceArray);
						if (basicDescription.parentalGuidanceArray[0] != null && 
							basicDescription.parentalGuidanceArray[0] != null && 
							basicDescription.parentalGuidanceArray[0].parentalRating !=null) { 
						
							prgItem.parentalGuidance = basicDescription.parentalGuidanceArray[0].parentalRating.href;
						}
					}
					//for ReleaseDate
					if (basicDescription.releaseInformationArray != null && 
						basicDescription.releaseInformationArray.length > 0 &&
						basicDescription.releaseInformationArray[0].releaseDate != null) {
						prgItem.releaseDate =  basicDescription.releaseInformationArray[0].releaseDate.dayAndYear;
					}
					programItems.push(prgItem);
	            }
	  		}
			return programItems;
		}
		
		/**
		 * Note : This method will be checked and removed later
		 * 
		 * Convert the xml object into programItems
		 *
		 * @param xmlObj TVA main object
		 * @return array of programItems
		 */
		public static function getPrograms(xmlObj:Object):Array {
			
			var programItems:Array = new Array();
			var xmlnode:XMLNode = xmlObj[0];
			if (xmlnode == null) return programItems;
			if (xmlnode.toString().indexOf("InvalidFragments") != -1) return programItems;
			var xmlchildnode:XMLNode = xmlnode.childNodes[1].childNodes[1].childNodes[1];
			var prgItem:ProgramItem;
           	var basicContentDescription:XML;
           	var mediatitle:XML;
			for each (xmlnode in xmlchildnode.childNodes) {
            	if (xmlnode.nodeName != null) {
            		basicContentDescription = new XML(xmlnode.childNodes[1].toString());
					prgItem = new ProgramItem();
					prgItem.title = MetasoftUtils.getCData(basicContentDescription.Title);
					prgItem.synopsis = MetasoftUtils.getCSV(basicContentDescription.Synopsis);
					prgItem.thumbnail = MetasoftUtils.getCData(basicContentDescription.Thumbnail);
					prgItem.preview = MetasoftUtils.getImageURI(MetasoftUtils.getCData(basicContentDescription.Preview));
					if (basicContentDescription.Keyword)
						prgItem.tags = MetasoftUtils.getStringAsArray(MetasoftUtils.getCSV(basicContentDescription.Keyword),",");
					if (basicContentDescription.Cost)	
						prgItem.price = MetasoftUtils.getCost(basicContentDescription.Cost);
					else prgItem.price = "0.0";
					//prgItem.rating = new Number("3");
					prgItem.thumbnailStream = MetasoftUtils.getArray(basicContentDescription.MediaTitle);
					//for genre
					var genreVals:Array = MetasoftUtils.getStringAsArray(MetasoftUtils.getCSV(basicContentDescription.Genre.Name),",");
					prgItem.content    = getGenre(basicContentDescription.Genre,"ContentCS",genreVals);
					prgItem.intentions = getGenre(basicContentDescription.Genre,"IntentionCS",genreVals);
					prgItem.atmosphere = getGenre(basicContentDescription.Genre,"AtmosphereCS",genreVals);
					prgItem.format     = getGenre(basicContentDescription.Genre,"FormatCS",genreVals);
					prgItem.intendedAudience  = getGenre(basicContentDescription.Genre,"IntendedAudienceCS",genreVals);
					prgItem.mediaType  = getGenre(basicContentDescription.Genre,"MediaTypeCS",genreVals);
					
					var temp:Array = new Array();
					for each (var img:String in prgItem.thumbnailStream) {
						
						temp.push(img.substring(img.indexOf("<MediaUri>") + 10, img.indexOf("</MediaUri>")));
					}
					prgItem.thumbnailStream = temp;

					temp = MetasoftUtils.getArray(basicContentDescription.RelatedMaterial);
					prgItem.relatedMaterial = new Array();
					var i:int = 0;
					var officialURI:String = "";
					for each (var rm:String in temp) {
						
						var icon:String = "";
						var link:String = "";
						if (rm.indexOf("<PromotionalMedia>") != -1) {
							
							icon = rm.substring(rm.indexOf("<PromotionalMedia>") + 18, rm.indexOf("</PromotionalMedia>"));
							if (icon.indexOf("<MediaUri>") != -1) {
								
								icon = icon.substring(icon.indexOf("<MediaUri>") + 10, icon.indexOf("</MediaUri>"));
							} else icon = prgItem.thumbnail;
						} else {
							icon = prgItem.thumbnail;
						}
						
						if (rm.indexOf("<MediaLocator>") != -1) {
							
							link = rm.substring(rm.indexOf("<MediaLocator>") + 14, rm.indexOf("</MediaLocator>"));
							if (link.indexOf("<MediaUri") != -1) {
								
								link = link.substring(link.indexOf("<MediaUri") + link.indexOf(">") - 4, link.indexOf("</MediaUri>"));
							}
						}
						link = MetasoftUtils.getURI(link);
						prgItem.relatedMaterial[i] = [icon,link];
						officialURI = link;
						i++;
						
					}
					//for OfficialURI
					if(officialURI) {
						prgItem.officialURI = officialURI;
				    }	
					// for trailers
					var tmp:Array = MetasoftUtils.getArray(basicContentDescription.RelatedMaterial);
					var j:int = 0;
					for each (var tv:String in tmp) {
						
						if (tv.indexOf("<PromotionalMedia>") != -1) {
							tv = tv.substring(tv.indexOf("<PromotionalMedia>") + 18, tv.indexOf("</PromotionalMedia>"));
							
							if (tv.indexOf("<TitleVideo ") != -1) {
								tv = tv.substring(tv.indexOf("<TitleVideo ") + 12, tv.indexOf("</TitleVideo>"));
								
								if (tv.indexOf("<MediaUri") != -1) {
									prgItem.trailers[j++] = tv.substring(tv.indexOf("<MediaUri>")+ 10 , tv.indexOf("</MediaUri>"));
								}
							}
						}
					}
					// for credit items
					prgItem.creditItems = getCreditItemsAsArrayCollection(basicContentDescription.CreditsList.CreditsItem);
					// for parental guidance
					prgItem.parentalGuidance = getParentalGuidanceAsArray(basicContentDescription.ParentalGuidance);
					programItems.push(prgItem);
					//for ReleaseDate
					prgItem.releaseDate =  basicContentDescription.ReleaseInformation.ReleaseDate.DayAndYear;
            	}
			}
			return programItems;
		}

		/**
		 * Convert CreditItem XML Object in to ArrayCollection 
		 * @param cInfo - CreditItems
		 * @return converted arraycollection object 
		 */
		public static function getCreditItemsAsArrayCollection(cInfo:XMLList):Array {
			if (cInfo == null) return new Array();
			
			var aC:Array = new Array();
			
			for (var j:int = 0; j < cInfo.length(); j++) {
				var ci:String = cInfo[j];
				var cItem:CreditItemInfo = new CreditItemInfo();		
				
				if (ci.indexOf("<CreditsItem ") != -1) {
					var c2:String = ci.substring(ci.indexOf("<CreditsItem role=\"") + 18, ci.indexOf(">") - 1);
					cItem.role = c2.substring(c2.lastIndexOf(":") + 1);
					if (ci.indexOf("<PersonName>") != -1) {
						var c1:String = ci.substring(ci.indexOf("<PersonName>") + 12, ci.indexOf("</PersonName>"));
						cItem.fname = MetasoftUtils.getCData(c1.substring(c1.indexOf("<GivenName") + 33 , ci.indexOf("</GivenName>")));
						
						if (ci.indexOf("<FamilyName") != -1) {
							cItem.lname = MetasoftUtils.getCData(ci.substring(ci.indexOf("<FamilyName") + 33 , ci.indexOf("</FamilyName>")));								
						}
					}						
				}
				aC.push(cItem);
			}
			return aC;
		}

		/**
		 * Convert ParentalGuidance XML Object into Array
		 * @param pgInfo - XMLList
		 * @return converted array object 
		 */
		public static function getParentalGuidanceAsArray(pgInfo:XMLList):Array {
			if (pgInfo == null) return new Array();
			
			var pg:Array = new Array();
			
			for (var j:int = 0; j < pgInfo.length(); j++) {
				var ci:String = pgInfo[j];
				
				if (ci.indexOf("<ParentalGuidance") != -1) {
					var c2:String = ci.substring(ci.indexOf("<ParentalRating href=\"") + 22, ci.lastIndexOf("=") - 7);
					pg.push(c2);
				}
			}
			return pg;
		}

		/**
		 * Convert Genre XML Object into Array
		 * @param pgInfo - XMLList
		 * @return converted array object 
		 */
		public static function getGenre(pgInfo:XMLList,typeGenre:String,genreVals:Array):Array {
			if (pgInfo == null) return new Array();
			
			var pg:Array = new Array();
			
			for (var j:int = 0; j < pgInfo.length(); j++) {
				
				var genreInfo:XMLList = pgInfo[j].attribute("href");
				var gType:String = genreInfo[0].split(":")[4];
				if(typeGenre == gType) {
					pg.push(genreVals[j]);
				}
			}
			return pg;
		}
		
		/**
		 * Convert Genre XML Object into Array
		 * @param pgInfo - XMLList
		 * @return converted array object 
		 */
		public static function getGenreFromProxy(genreArray:ArrayCollection,typeGenre:String):Array {
			if (genreArray == null) return new Array();
			var genre:Object;
			var pg:Array = new Array();
			for each(genre in genreArray){
				if (genre == null) continue;
				var href:String  = genre.href;
				if (href != null){
					if (href.indexOf(typeGenre) != -1){
						pg.push(genre.Name);
					}
				}
			}
			return pg;
		}
		
		/**
		 * Convert Genre XML Object into Array
		 * @param pgInfo - XMLList
		 * @return converted array object 
		 */
		public static function getGenreFromObject(genreArray:Array,typeGenre:String, product : Product):Array {

			if (genreArray == null) {
				return new Array();
			}
			var genre:Object;
			var pg:Array = new Array();
		 	var i : int = 1;
			for each(genre in genreArray) {

				if (genre == null) { 
					continue;
				}
				var href:String  = genre.href;
				if (href != null) {

					if (href.indexOf(typeGenre) != -1 && 
						genre.name != null){

//						pg.push(genre.name.stringValue, genre.name.stringValue);
						pg[genre.name.stringValue] = genre.name.stringValue;
						pg.length = i;
						i++;

						var genreType:GenreType = new GenreType();
						genreType.type = genre.name.stringValue;
						if (typeGenre == "ContentCS") {

							if (product.contentArray == null) {
								product.contentArray = new Array();
							}
							product.contentArray.push(genreType);
						} else if (typeGenre == "ContentTypeCS") {

							if (product.contentTypeArray == null) {
								product.contentTypeArray = new Array();
							}
							product.contentTypeArray.push(genreType);
						} else if (typeGenre == "IntentionCS") {

							if (product.intentionsArray == null) {
								product.intentionsArray = new Array();
							}
							product.intentionsArray.push(genreType);
						} else if (typeGenre == "AtmosphereCS") {

							if (product.atmosphereArray == null) {
								product.atmosphereArray = new Array();
							}
							product.atmosphereArray.push(genreType);
						} else if (typeGenre == "FormatCS") {

							if (product.formatArray == null) {
								product.formatArray = new Array();
							}
							product.formatArray.push(genreType);
						} else if (typeGenre == "IntendedAudienceCS") {

							if (product.intendedAudienceArray == null) {
								product.intendedAudienceArray = new Array();
							}
							product.intendedAudienceArray.push(genreType);
						} else if (typeGenre == "Origination") {

							if (product.originationArray == null) {
								product.originationArray = new Array();
							}
							product.originationArray.push(genreType);
						} else if (typeGenre == "ContentAlert") {

							if (product.contentAlertArray == null) {
								product.contentAlertArray = new Array();
							}
							product.contentAlertArray.push(genreType);
						} 
					}
				}
			}
			return pg;
		}

		/**
		 * Returns all the child category names as an Array
		 */ 
		public static function getCategoryChildren(categoryName:String):Array {
			
			var root:XML = MetasoftULC.CategoryXML;
			var categories:Array = new Array();
			categories.push(categoryName);
			if (root == null) return categories;
			if (root.toXMLString().indexOf(categoryName) == -1) return categories;
			
			var nodeList:XMLList = root.node;
			var node:XMLList = nodeList.(@label == categoryName);
			while (node == null || node.length() == 0) {
				nodeList = nodeList.node;
				node = nodeList.(@label == categoryName);
			}
			for each (var nodeX:XML in node) {
				updateCategoryChildren(nodeX.children(), categories);
			}
			return categories;
		}
		
		/**
		 * Updates the category array with child elements
		 */
		private static function updateCategoryChildren(children:XMLList, categories:Array):void {
			
			if (children == null && children.length() == 0) return;
			
			for each (var child:XML in children) {
				var childLabel:String = child.attribute("label");
				categories.push(childLabel);
				updateCategoryChildren(child.children(), categories);
			}
		}
		
	    /**
		 * Return getData query based on the Search Criteria
		 */
		public static function getKeywordCriteria(searchValue:String):GetDataDocument {

			var getDataDoc:GetDataDocument 	= new GetDataDocument();
			var getDataType:GetDataType 	= new GetDataType();
			var queryConstraints:QueryConstraintsInfo = new QueryConstraintsInfo();

//			var predicateBag:PredicateBagType = new PredicateBagType();

//			predicateBag.contextNode 	= "ProgramInformation";
//			predicateBag.type 			= "OR";

			var wholePredicateBag:PredicateBagType = new PredicateBagType();
			wholePredicateBag.type		= "AND";

			var negatepredicateBag:PredicateBagType 		= new PredicateBagType();
			var titleBinaryPredicate:BinaryPredicateType 	= new BinaryPredicateType();
			var synopsisBinaryPredicate:BinaryPredicateType = new BinaryPredicateType();
			var keywordBinaryPredicate:BinaryPredicateType 	= new BinaryPredicateType();
			//negatepredicateBag.contextNode = "ProgramInformation";
			negatepredicateBag.type = "OR";
			negatepredicateBag.negate = false;

			titleBinaryPredicate 	= createBinaryPredicate(MetasoftULC.Field_Title, searchValue, MetasoftULC.operator_Contains);
			keywordBinaryPredicate 	= createBinaryPredicate(MetasoftULC.Field_Keyword, searchValue, MetasoftULC.operator_Contains);
			synopsisBinaryPredicate = createBinaryPredicate(MetasoftULC.Field_Synopsis, searchValue, MetasoftULC.operator_Contains);

			negatepredicateBag.binaryPredicateArray = new Array();
			negatepredicateBag.binaryPredicateArray.push(titleBinaryPredicate);
			negatepredicateBag.binaryPredicateArray.push(keywordBinaryPredicate);
			negatepredicateBag.binaryPredicateArray.push(synopsisBinaryPredicate);

//			predicateBag.predicateBagArray 	= new Array();
//			predicateBag.predicateBagArray.push(negatepredicateBag);
			
			var copyRightsPredicateBag:PredicateBagType = new PredicateBagType();
			copyRightsPredicateBag.type 		= "OR";
			copyRightsPredicateBag.negate 		= true;
			copyRightsPredicateBag.binaryPredicateArray = new Array();
			var copyRightsBinaryPredicate:BinaryPredicateType = new BinaryPredicateType();
			copyRightsBinaryPredicate.test 		 = MetasoftULC.operator_Contains;
			copyRightsBinaryPredicate.fieldID 	 = MetasoftULC.Field_CopyRight;
			copyRightsBinaryPredicate.fieldValue = MetasoftULC.Privacy_Private;
			copyRightsPredicateBag.binaryPredicateArray.push(copyRightsBinaryPredicate);

			wholePredicateBag.predicateBagArray = new Array();
			wholePredicateBag.predicateBagArray.push(negatepredicateBag);
			wholePredicateBag.predicateBagArray.push(copyRightsPredicateBag);

			queryConstraints.predicateBag = wholePredicateBag;

			getDataType.queryConstraints 	= queryConstraints;
			getDataType.personalInfoUse		= false;

			var requestedTables:RequestedTablesType = new RequestedTablesType();
			var table:TableType = new TableType();
			table.type = "ProgramInformationTable";
			
			requestedTables.tableArray = new Array();
			requestedTables.tableArray.push(table);
			getDataType.requestedTables = requestedTables;

			getDataDoc.getData = getDataType;

			return getDataDoc;
		}
		
		/**
		 * Method to get the UploadPersonalDataType obj for the given userName and password
		 * */
		public static function getUploadDataDocument(regProfileInfo : ProfileInfo):UploadPersonalDataDocument{

			var uploadPersonalDataDocument:UploadPersonalDataDocument = new UploadPersonalDataDocument();
			var uploadPersonalDatatype:UploadPersonalDataType = new UploadPersonalDataType();
			var userPreferencesType : UserPreferencesType = new UserPreferencesType();
			userPreferencesType.userIdentifier = new UserIdentifierType();
			userPreferencesType.userIdentifier.name = new TextualType();
			userPreferencesType.userIdentifier.name.stringValue = regProfileInfo.userId;
			var extendedUserDescriptionType:ExtendedUserDescriptionType = new ExtendedUserDescriptionType();
			var userInformationTableType:UserInformationTableType = new UserInformationTableType();
			var userInformationType:UserInformationType = new UserInformationType();
			var biographicInformationType:BiographicInformationType = new BiographicInformationType();
			var personNameType:PersonNameType = new PersonNameType();
			var gN:NameComponentType = new NameComponentType;
			gN.givenName = regProfileInfo.firstName;
			gN.stringValue = regProfileInfo.firstName;
			personNameType.givenNameArray = new Array();
			personNameType.givenNameArray.push(gN);
			var lN:NameComponentType = new NameComponentType;
			lN.linkingName = regProfileInfo.password;
			lN.stringValue = regProfileInfo.password;
			personNameType.linkingNameArray = new Array();
			personNameType.linkingNameArray.push(lN);
			var fN:NameComponentType = new NameComponentType;
			fN.familyName = regProfileInfo.lastName;
			fN.stringValue = regProfileInfo.lastName;
			personNameType.familyNameArray = new Array();
			personNameType.familyNameArray.push(fN);
			biographicInformationType.nameArray = new Array();
			biographicInformationType.nameArray.push(personNameType);
			biographicInformationType.age = Number(regProfileInfo.age);
			biographicInformationType.gender = regProfileInfo.gender;
			userInformationType.biographicInformationArray = new Array();
			userInformationType.biographicInformationArray.push(biographicInformationType);
			userInformationTableType.userInformationArray = new Array();
			userInformationTableType.userInformationArray.push(userInformationType);
			userInformationType.userInformationId = regProfileInfo.userId;
			extendedUserDescriptionType.userInformationTable = userInformationTableType;
			extendedUserDescriptionType.userPreferences = userPreferencesType;
			uploadPersonalDatatype.userInformationArray = new Array();
			uploadPersonalDatatype.userInformationArray.push(extendedUserDescriptionType);
			uploadPersonalDataDocument.uploadPersonalData = uploadPersonalDatatype;
			return uploadPersonalDataDocument;
		}
		
		/**
		 * Method to get the sample GetDataType obj
		 */
		public static function getGetDataDocument(so:SharedObject):GetDataDocument {

			var getDataDoc:GetDataDocument = new GetDataDocument();
			var userPreferencesObject : UserPreferencesType = new UserPreferencesType();
			var userPreferences:UserPreferencesType = so.data.preference;
			var usageHistoryType:UsageHistoryType = so.data.profileInfo.usageHistory;
			var userInformationTable:UserInformationTableType = so.data.profileInfo.userInformationTable;
			var getDataType:GetDataType = new GetDataType();
			var quesrConstraints:QueryConstraintsInfo = new QueryConstraintsInfo();
			var requestedTables:RequestedTablesType = new RequestedTablesType();
			
			var infoTable:TableType = new TableType();
			infoTable.type = "ProgramInformationTable";
//			var reviewTable:TableType = new TableType();
//			reviewTable.type = "ProgramReviewTable";
			requestedTables.tableArray = new Array();
			requestedTables.tableArray.push(infoTable);
//			requestedTables.tableArray.push(reviewTable);
			getDataType.requestedTables = requestedTables;
			var predicateBag:PredicateBagType = new PredicateBagType();
			predicateBag.type = "AND";
			predicateBag.predicateBagArray = new Array();
			predicateBag.binaryPredicateArray = new Array();
			var existsAtleasetOne:Boolean = false;
			var binaryPredicate:BinaryPredicateType = null;
			
			var binaryPredicateCRID:BinaryPredicateType = new BinaryPredicateType();
			
			var personalInformation :ExtendedUserDescriptionType = null;
			var negatepredicateBag:PredicateBagType = new PredicateBagType();
			var CRID : String = "";

			if (userPreferences != null || 
				usageHistoryType != null || 
				userInformationTable != null) {
				personalInformation = new ExtendedUserDescriptionType();
			}
			if (userPreferences != null) {

				var filteringAndSearchPrefArray:Array = userPreferences.filteringAndSearchPreferencesArray;
				if (filteringAndSearchPrefArray != null) {

					for(var i:int; i < filteringAndSearchPrefArray.length; i++) {
	
						if (filteringAndSearchPrefArray[i] != null) {


							var filteringAndSerachPref:FilteringAndSearchPreferencesType = filteringAndSearchPrefArray[i];
							if (filteringAndSerachPref == null) {
								continue;
							}
							var classificationPrefArray:Array = filteringAndSerachPref.classificationPreferencesArray;
							if (classificationPrefArray != null ) {
		
								var classicpredicateBag:PredicateBagType = new PredicateBagType();
//								classicpredicateBag.contextNode = "ProgramInformation";
								classicpredicateBag.type = "OR";
								classicpredicateBag.predicateBagArray = new Array();
								classicpredicateBag.binaryPredicateArray = new Array();
								var isFormatCinema:Boolean = false;
								var classificationPreferencesType:ClassificationPreferencesType = new ClassificationPreferencesType();
								var filteringAndSearchPreferencesType:FilteringAndSearchPreferencesType = new FilteringAndSearchPreferencesType();
								classificationPreferencesType.genreArray = new Array();
								filteringAndSearchPreferencesType.classificationPreferencesArray = new Array();
								userPreferencesObject.filteringAndSearchPreferencesArray = new Array();
								for (var j:int =0; j < classificationPrefArray.length; j++) {

									var classificationPref:ClassificationPreferencesType =classificationPrefArray[j];
									var genreArray: Array = classificationPref.genreArray;

									var genreCount : int = 0;
									for (genreCount = 0; genreCount < genreArray.length; genreCount++) {
								
										var genreObject:Genre = genreArray[genreCount];
										if (genreObject != null) {
											
											var preferenceValue : int 	= genreObject.preferenceValue;
											var href:String   			= genreObject.href;
											
											if (genreObject.nameArray != null) {
												
												var genreNameCount : int = 0;
												for (genreNameCount = 0; genreNameCount < genreObject.nameArray.length; genreNameCount++) {

													if (genreObject.nameArray[genreNameCount] != null) {

														var genreNameType : NameType = genreObject.nameArray[genreNameCount]
														if (genreNameType != null) {

															var genreName :String = genreNameType.stringValue
															if (MetasoftULC.queryAll) {
																var childGenreArray:Array = MetasoftHelper.getCategoryChildren(genreName);
															} else {

																childGenreArray = new Array();
																childGenreArray.push(genreName);
															}
															for (var childCount:int = 0; childCount < childGenreArray.length; childCount ++){
											
																var genre:Genre = new Genre();
																genre = createGenre(preferenceValue,childGenreArray[childCount],href);
																classificationPreferencesType.genreArray.push(genre);
															}
														}
													}
												}
											}
										}
									}
									filteringAndSearchPreferencesType.classificationPreferencesArray.push(classificationPreferencesType);
//									userPreferencesObject.filteringAndSearchPreferencesArray.push(filteringAndSearchPreferencesType);
									
									if (genreArray == null ) { 
										continue; 
									}
									if (genreArray.length > 0 ) {
										existsAtleasetOne = true;
									}
									for(var k:int = 0; k < genreArray.length; k++) {
		
										var genreType:Genre = genreArray[k];
										if (genreType != null && genreType.nameArray[0] != null) {
		
											if (MetasoftULC.queryAll) {

												var genreSubArray:Array = MetasoftHelper.getCategoryChildren(genreType.nameArray[0].stringValue);
												var genreSubCount : int = 0;
												for (genreSubCount = 0; genreSubCount < genreSubArray.length; genreSubCount++) {

													binaryPredicate = createBinaryPredicate(MetasoftULC.Field_Genre, genreSubArray[genreSubCount], MetasoftULC.operator_Contains);
													classicpredicateBag.binaryPredicateArray.push(binaryPredicate);
												}
											} else if (MetasoftULC.Format_Movie == genreType.nameArray[0].name ||
												MetasoftULC.Format_Cinema == genreType.nameArray[0].name ) {
												
												binaryPredicate = createBinaryPredicate(MetasoftULC.Field_Genre,MetasoftULC.Format_Cinema,MetasoftULC.operator_Contains);
												predicateBag.predicateBagArray.push(binaryPredicate);
												isFormatCinema = true;
											} else {
				
												binaryPredicate = createBinaryPredicate(MetasoftULC.Field_Genre,genreType.nameArray[0].stringValue,MetasoftULC.operator_Contains);
												classicpredicateBag.binaryPredicateArray.push(binaryPredicate);
											}
										}
									}
								}
							}
							if (!isFormatCinema) {
		
//								negatepredicateBag.contextNode = "ProgramInformation";
								/*negatepredicateBag.type = "AND";
								negatepredicateBag.negate = true;
								negatepredicateBag.binaryPredicateArray = new Array();
								binaryPredicate=createBinaryPredicate(MetasoftULC.Field_Genre, MetasoftULC.Format_Cinema, MetasoftULC.operator_Equals);
								var newBinaryPredicate:BinaryPredicateType = createBinaryPredicate("Copyright", "Private", MetasoftULC.operator_Contains);
								negatepredicateBag.binaryPredicateArray.push(newBinaryPredicate);
								negatepredicateBag.binaryPredicateArray.push(binaryPredicate);
								predicateBag.predicateBagArray.push(negatepredicateBag);*/
								predicateBag.type = "OR";
								predicateBag.negate = true;
								predicateBag.binaryPredicateArray = new Array();
								binaryPredicate = createBinaryPredicate(MetasoftULC.Field_Genre, MetasoftULC.Format_Cinema, MetasoftULC.operator_Contains);
								var copyBinaryPredicate:BinaryPredicateType = createBinaryPredicate("Copyright", "Private", MetasoftULC.operator_Equals);
								predicateBag.binaryPredicateArray.push(copyBinaryPredicate);
								predicateBag.binaryPredicateArray.push(binaryPredicate);
							}
							var creationPreferenceArray:Array = filteringAndSerachPref.creationPreferencesArray;
							if (creationPreferenceArray == null ) {
								
								if(classicpredicateBag != null && classicpredicateBag.binaryPredicateArray.length != 0) {
									predicateBag.predicateBagArray.push(classicpredicateBag);
								}
								continue;
							}
							if (classicpredicateBag ==null) {
		
								classicpredicateBag = new PredicateBagType();
//								classicpredicateBag.contextNode = "ProgramInformation";
								classicpredicateBag.type = "OR";
								classicpredicateBag.predicateBagArray = new Array();
								classicpredicateBag.binaryPredicateArray = new Array();
							}
							if (filteringAndSearchPreferencesType == null) {
								filteringAndSearchPreferencesType = new FilteringAndSearchPreferencesType();
							}
							filteringAndSearchPreferencesType.creationPreferencesArray = new Array()
							for (j = 0; j <creationPreferenceArray.length; j++) {
								
								var creationPref:CreationPreferencesType = creationPreferenceArray[j];
								var creatorArray: Array = creationPref.creatorArray;
								if (creatorArray == null ) {
									continue;
								}
								for(k = 0; k <creatorArray.length; k ++) {
		
									var creator:CreatorType = creatorArray[k];
									var nameArray:Array  = null;
									if (creator == null) { 
										continue; 
									}
									var role:ControlledTermUseType = creator.role;
									if (role == null || role.nameArray == null) {
										continue;
									}
									nameArray = role.nameArray;
									if (nameArray == null) { 
										continue; 
									}
									if (nameArray.length > 0 ) {
										existsAtleasetOne = true;
									}
									for(var l:int = 0; l <nameArray.length; l ++) {
		
										var name:NameType =nameArray[l];
										if (name == null || 
											name.stringValue == null || 
											name.stringValue  == "null" ||
											name.stringValue.length == 0) { 
												continue;
										}
										binaryPredicate = createBinaryPredicate(MetasoftULC.Field_CreditName, name.stringValue, MetasoftULC.operator_Equals);
										classicpredicateBag.binaryPredicateArray.push(binaryPredicate);
									}
								}
								filteringAndSearchPreferencesType.creationPreferencesArray.push(creationPref);
							}
							if (userPreferencesObject.filteringAndSearchPreferencesArray == null ) {
								userPreferencesObject.filteringAndSearchPreferencesArray = new Array();
							}
							userPreferencesObject.filteringAndSearchPreferencesArray.push(filteringAndSearchPreferencesType);
							if (classicpredicateBag.binaryPredicateArray.length != 0)  {
								predicateBag.predicateBagArray.push(classicpredicateBag);
							}
						}
					}
				}
				if (userPreferences.userIdentifier != null
					&& userPreferences.userIdentifier.name != null) {

					var userIdentifierObj:UserIdentifierType = new UserIdentifierType();
					userIdentifierObj.name = new TextualType();
					userIdentifierObj.name.stringValue 	= userPreferences.userIdentifier.name.stringValue;
					userIdentifierObj.name.name			= userPreferences.userIdentifier.name.stringValue;
					userPreferencesObject.userIdentifier 	= userIdentifierObj;
				}
				personalInformation.userPreferences= userPreferencesObject;
			}
			if(usageHistoryType != null) {
				personalInformation.usageHistory =usageHistoryType;
			}
			if(userInformationTable != null) {
				personalInformation.userInformationTable = userInformationTable;
			}
			getDataType.personalInformation =personalInformation;
			if (!existsAtleasetOne) {

//				negatepredicateBag.contextNode = "ProgramInformation";
				/*negatepredicateBag.type = "AND";
				negatepredicateBag.negate = true;
				negatepredicateBag.binaryPredicateArray = new Array();
				binaryPredicate = createBinaryPredicate(MetasoftULC.Field_Genre, MetasoftULC.Format_Cinema, MetasoftULC.operator_Contains);
				var copyBinaryPredicate:BinaryPredicateType = createBinaryPredicate("Copyright", "Private", MetasoftULC.operator_Equals);
				negatepredicateBag.binaryPredicateArray.push(copyBinaryPredicate);
				negatepredicateBag.binaryPredicateArray.push(binaryPredicate);
				predicateBag.predicateBagArray.push(negatepredicateBag);*/
				predicateBag.type = "OR";
				predicateBag.negate = true;
				predicateBag.binaryPredicateArray = new Array();
				binaryPredicate = createBinaryPredicate(MetasoftULC.Field_Genre, MetasoftULC.Format_Cinema, MetasoftULC.operator_Contains);
				var copyBinaryPredicate:BinaryPredicateType = createBinaryPredicate("Copyright", "Private", MetasoftULC.operator_Contains);
				predicateBag.binaryPredicateArray.push(copyBinaryPredicate);
				predicateBag.binaryPredicateArray.push(binaryPredicate);
//				predicateBag.binaryPredicateArray =new Array();
//				predicateBag.binaryPredicateArray.push(binaryPredicate);
			}
			
//			binaryPredicateCRID = createBinaryPredicate("CRID", CRID, MetasoftULC.operator_Contains);
//			predicateBag.binaryPredicateArray = new Array();
//			predicateBag.binaryPredicateArray.push(binaryPredicateCRID);
				
			quesrConstraints.predicateBag = predicateBag;
			getDataType.queryConstraints = quesrConstraints;
			getDataType.maxPrograms =MetasoftULC.default_MAXPrograms;
			getDataDoc.getData = getDataType;
			return getDataDoc;
		}
		
		/**
		 * Method to get the sample GetDataType obj
		 */
		public static function getCreditCriteria(stringValue:String):GetDataDocument {

			var getDataDoc:GetDataDocument = new GetDataDocument();
			var getDataType:GetDataType = new GetDataType();

			var requestedTables:RequestedTablesType = new RequestedTablesType();
			var table:TableType = new TableType();
			table.type = "ProgramInformationTable";
			/*var tableReview:TableType = new TableType();
			tableReview.type = "ProgramReviewTable";
			requestedTables.tableArray.push(tableReview);*/
			requestedTables.tableArray = new Array();
			requestedTables.tableArray.push(table);
			getDataType.requestedTables = requestedTables;
			getDataType.personalInfoUse = false;

			var quesrConstraints:QueryConstraintsInfo = new QueryConstraintsInfo();

			var predicateBag:PredicateBagType = new PredicateBagType();

			var wholePredicateBag:PredicateBagType = new PredicateBagType();
			wholePredicateBag.type		= "AND";
			
//			predicateBag.contextNode 	= "ProgramInformation";
			predicateBag.type 			= "AND";
			predicateBag.binaryPredicateArray = new Array();
			var binaryPredicate:BinaryPredicateType = new BinaryPredicateType();
			binaryPredicate.test 		= MetasoftULC.operator_Contains;
			binaryPredicate.fieldID 	= MetasoftULC.Field_CreditName;
			binaryPredicate.fieldValue 	= stringValue;
			predicateBag.binaryPredicateArray.push(binaryPredicate);
			
			var copyRightsPredicateBag:PredicateBagType = new PredicateBagType();
			copyRightsPredicateBag.type 		= "OR";
			copyRightsPredicateBag.negate 		= true;
			copyRightsPredicateBag.binaryPredicateArray = new Array();
			var copyRightsBinaryPredicate:BinaryPredicateType = new BinaryPredicateType();
			copyRightsBinaryPredicate.test 		 = MetasoftULC.operator_Contains;
			copyRightsBinaryPredicate.fieldID 	 = MetasoftULC.Field_CopyRight;
			copyRightsBinaryPredicate.fieldValue = MetasoftULC.Privacy_Private;
			copyRightsPredicateBag.binaryPredicateArray.push(copyRightsBinaryPredicate);

			wholePredicateBag.predicateBagArray = new Array();
			wholePredicateBag.predicateBagArray.push(predicateBag);
			wholePredicateBag.predicateBagArray.push(copyRightsPredicateBag);

			quesrConstraints.predicateBag = wholePredicateBag;
			
			getDataType.queryConstraints = quesrConstraints;
			getDataType.maxPrograms =MetasoftULC.default_MAXPrograms;
			getDataDoc.getData = getDataType;
			return getDataDoc;
		}

		/**
		 * Method to get the sample GetDataType obj
		 */
		public static function getRatingCriteria(stringValue:Array):GetDataDocument {

			var getDataDoc:GetDataDocument = new GetDataDocument();
			var getDataType:GetDataType = new GetDataType();

			var requestedTables:RequestedTablesType = new RequestedTablesType();
			var table:TableType = new TableType();
			table.type = "ProgramInformationTable";
			var tableReview:TableType = new TableType();
			tableReview.type = "ProgramReviewTable";
			requestedTables.tableArray = new Array();
			requestedTables.tableArray.push(table);
			requestedTables.tableArray.push(tableReview);
			getDataType.requestedTables = requestedTables;
			
			getDataType.personalInfoUse = false;
			
			var quesrConstraints:QueryConstraintsInfo = new QueryConstraintsInfo();

			var predicateBag:PredicateBagType = new PredicateBagType();
//			predicateBag.contextNode 	= "ProgramInformation";
			predicateBag.type 			= "AND";
			predicateBag.binaryPredicateArray = new Array();
			var binaryPredicateMin:BinaryPredicateType = new BinaryPredicateType();
			binaryPredicateMin.test 		= "greater_than";
			binaryPredicateMin.fieldID 		= "RatingValue";
			binaryPredicateMin.fieldValue 	= stringValue[0];
			
			var binaryPredicateMax:BinaryPredicateType = new BinaryPredicateType();
			binaryPredicateMax.test 		= "less_than";
			binaryPredicateMax.fieldID 		= "RatingValue";
			binaryPredicateMax.fieldValue 	= stringValue[1];
			
			predicateBag.binaryPredicateArray.push(binaryPredicateMin);
			predicateBag.binaryPredicateArray.push(binaryPredicateMax);

			var predicateBagObject:PredicateBagType = new PredicateBagType();
			var binaryPredicate:BinaryPredicateType = new BinaryPredicateType();
			binaryPredicate.test 		= MetasoftULC.operator_Contains;
			binaryPredicate.fieldID 	= MetasoftULC.Field_CRID;
			binaryPredicate.fieldValue 	= "";
			predicateBagObject.type = "AND";
			predicateBagObject.binaryPredicateArray = new Array();
			predicateBagObject.binaryPredicateArray.push(binaryPredicate);
			
			var copyRightsPredicateBag:PredicateBagType = new PredicateBagType();
			copyRightsPredicateBag.type 		= "OR";
			copyRightsPredicateBag.negate 		= true;
			copyRightsPredicateBag.binaryPredicateArray = new Array();
			var copyRightsBinaryPredicate:BinaryPredicateType = new BinaryPredicateType();
			copyRightsBinaryPredicate.test 		 = MetasoftULC.operator_Contains;
			copyRightsBinaryPredicate.fieldID 	 = MetasoftULC.Field_CopyRight;
			copyRightsBinaryPredicate.fieldValue = MetasoftULC.Privacy_Private;
			copyRightsPredicateBag.binaryPredicateArray.push(copyRightsBinaryPredicate);
			
			predicateBagObject.predicateBagArray = new Array();
			predicateBagObject.predicateBagArray.push(predicateBag);
			predicateBagObject.predicateBagArray.push(copyRightsPredicateBag);
			
			quesrConstraints.predicateBag = predicateBagObject;
			
			getDataType.queryConstraints = quesrConstraints;
			getDataType.maxPrograms =MetasoftULC.default_MAXPrograms;
			getDataDoc.getData = getDataType;
			return getDataDoc;
		}

		/**
		 * Method to get the sample GetDataType obj
		 */
		public static function getCategoryCriteria(stringValue:String):GetDataDocument {

			var getDataDoc:GetDataDocument = new GetDataDocument();
			var getDataType:GetDataType = new GetDataType();

			var requestedTables:RequestedTablesType = new RequestedTablesType();
			var table:TableType = new TableType();
			table.type = "ProgramInformationTable";
			/*var tableReview:TableType = new TableType();
			tableReview.type = "ProgramReviewTable";
			requestedTables.tableArray.push(tableReview);*/
			requestedTables.tableArray = new Array();
			requestedTables.tableArray.push(table);
			getDataType.requestedTables = requestedTables;

			getDataType.personalInfoUse = false;
			
			var quesrConstraints:QueryConstraintsInfo = new QueryConstraintsInfo();
			
			var wholePredicateBag:PredicateBagType = new PredicateBagType();
			wholePredicateBag.type		= "AND";
			
			var predicateBag:PredicateBagType = new PredicateBagType();
//			predicateBag.contextNode 	= "ProgramInformation";
			predicateBag.type 			= "AND";
			predicateBag.binaryPredicateArray = new Array();
			var binaryPredicate:BinaryPredicateType = new BinaryPredicateType();
			binaryPredicate.test 		= MetasoftULC.operator_Contains;
			binaryPredicate.fieldID 	= MetasoftULC.Field_Genre;
			binaryPredicate.fieldValue 	= stringValue;
			predicateBag.binaryPredicateArray.push(binaryPredicate);

			var copyRightsPredicateBag:PredicateBagType = new PredicateBagType();
			copyRightsPredicateBag.type 		= "OR";
			copyRightsPredicateBag.negate 		= true;
			copyRightsPredicateBag.binaryPredicateArray = new Array();
			var copyRightsBinaryPredicate:BinaryPredicateType = new BinaryPredicateType();
			copyRightsBinaryPredicate.test 		 = MetasoftULC.operator_Contains;
			copyRightsBinaryPredicate.fieldID 	 = MetasoftULC.Field_CopyRight;
			copyRightsBinaryPredicate.fieldValue = MetasoftULC.Privacy_Private;
			copyRightsPredicateBag.binaryPredicateArray.push(copyRightsBinaryPredicate);

			wholePredicateBag.predicateBagArray = new Array();
			wholePredicateBag.predicateBagArray.push(predicateBag);
			wholePredicateBag.predicateBagArray.push(copyRightsPredicateBag);
			/*var predicateBag1:PredicateBagType = new PredicateBagType();
//			predicateBag.contextNode 	= "ProgramInformation";
			predicateBag1.type 			= "AND";
			predicateBag1.binaryPredicateArray = new Array();
			var binaryPredicateMin:BinaryPredicateType = new BinaryPredicateType();
			binaryPredicateMin.test 		= "greater_than";
			binaryPredicateMin.fieldID 		= "RatingValue";
			binaryPredicateMin.fieldValue 	= "0";
			
			var binaryPredicateMax:BinaryPredicateType = new BinaryPredicateType();
			binaryPredicateMax.test 		= "less_than";
			binaryPredicateMax.fieldID 		= "RatingValue";
			binaryPredicateMax.fieldValue 	= "10";
			
			predicateBag1.binaryPredicateArray.push(binaryPredicateMin);
			predicateBag1.binaryPredicateArray.push(binaryPredicateMax);

			var predicateBagObject:PredicateBagType = new PredicateBagType();
			var binaryPredicate:BinaryPredicateType = new BinaryPredicateType();
			binaryPredicate.test 		= MetasoftULC.operator_Contains;
			binaryPredicate.fieldID 	= MetasoftULC.Field_CRID;
			binaryPredicate.fieldValue 	= "";
			predicateBagObject.type = "OR";
			predicateBagObject.binaryPredicateArray = new Array();
			predicateBagObject.binaryPredicateArray.push(binaryPredicate);
			predicateBagObject.predicateBagArray = new Array();
			predicateBagObject.predicateBagArray.push(predicateBag);
			predicateBagObject.predicateBagArray.push(predicateBag1);*/
			
			quesrConstraints.predicateBag = wholePredicateBag;

			getDataType.queryConstraints = quesrConstraints;
			getDataType.maxPrograms =MetasoftULC.default_MAXPrograms;
			getDataDoc.getData = getDataType;
			return getDataDoc;
		}

		/**
		 * Method to get the sample GetDataType obj
		 */
		public static function addUserPreference(searchPredicateBagArray : Array, searchBinaryPredicate : BinaryPredicateType):GetDataDocument {

			var so:SharedObject = SharedObject.getLocal(MetasoftULC.LoggedInUser);
			var getDataDoc:GetDataDocument = new GetDataDocument();
			var userPreferencesObject : UserPreferencesType = new UserPreferencesType();
			var userPreferences:UserPreferencesType = so.data.preference;
			var usageHistoryType:UsageHistoryType = so.data.profileInfo.usageHistory;
			var userInformationTable:UserInformationTableType = so.data.profileInfo.userInformationTable;
			var getDataType:GetDataType = new GetDataType();
			var quesrConstraints:QueryConstraintsInfo = new QueryConstraintsInfo();
			var requestedTables:RequestedTablesType = new RequestedTablesType();
			var table:TableType = new TableType();
			table.type = "ProgramInformationTable";
			requestedTables.tableArray = new Array();
			requestedTables.tableArray.push(table);
			var predicateBag:PredicateBagType = new PredicateBagType();
			if (searchBinaryPredicate == null) {

				predicateBag.type = "AND";
//				predicateBag.contextNode = "ProgramInformation";
			} else {

				predicateBag.type = "OR";
				var tableReview:TableType = new TableType();
				tableReview.type = "ProgramReviewTable";
				requestedTables.tableArray.push(tableReview);
			}
			getDataType.requestedTables = requestedTables;

			predicateBag.predicateBagArray = new Array();
			predicateBag.binaryPredicateArray = new Array();
			var existsAtleasetOne:Boolean = false;
			var binaryPredicate:BinaryPredicateType = null;
			var personalInformation :ExtendedUserDescriptionType = null;
			var negatepredicateBag:PredicateBagType = new PredicateBagType();
			if (searchPredicateBagArray != null && searchPredicateBagArray.length > 0) {
				
				var i : int = 0; 
				for (i = 0; i < searchPredicateBagArray.length; i++) {

					var newPredicateBag : PredicateBagType = searchPredicateBagArray[i] as PredicateBagType;
					predicateBag.predicateBagArray.push(newPredicateBag);
				}
			}
			if (searchBinaryPredicate != null) {
				predicateBag.binaryPredicateArray.push(searchBinaryPredicate);
			}
			if (userPreferences != null || 
				usageHistoryType != null || 
				userInformationTable != null) {
				personalInformation = new ExtendedUserDescriptionType();
			}
			if (userPreferences != null) {

				var filteringAndSearchPrefArray:Array = userPreferences.filteringAndSearchPreferencesArray;
				if (filteringAndSearchPrefArray != null) {

					for(var i:int; i < filteringAndSearchPrefArray.length; i++) {
	
						if (filteringAndSearchPrefArray[i] != null) {


							var filteringAndSerachPref:FilteringAndSearchPreferencesType = filteringAndSearchPrefArray[i];
							if (filteringAndSerachPref == null) {
								continue;
							}
							var classificationPrefArray:Array = filteringAndSerachPref.classificationPreferencesArray;
							if (classificationPrefArray != null ) {
		
								var classicpredicateBag:PredicateBagType = new PredicateBagType();
//								classicpredicateBag.contextNode = "ProgramInformation";
								classicpredicateBag.type = "OR";
								classicpredicateBag.predicateBagArray = new Array();
								classicpredicateBag.binaryPredicateArray = new Array();
								var isFormatCinema:Boolean = false;
								var classificationPreferencesType:ClassificationPreferencesType = new ClassificationPreferencesType();
								var filteringAndSearchPreferencesType:FilteringAndSearchPreferencesType = new FilteringAndSearchPreferencesType();
								classificationPreferencesType.genreArray = new Array();
								filteringAndSearchPreferencesType.classificationPreferencesArray = new Array();
								userPreferencesObject.filteringAndSearchPreferencesArray = new Array();
								for (var j:int =0; j < classificationPrefArray.length; j++) {

									var classificationPref:ClassificationPreferencesType =classificationPrefArray[j];
									var genreArray: Array = classificationPref.genreArray;

									var genreCount : int = 0;
									for (genreCount = 0; genreCount < genreArray.length; genreCount++) {
								
										var genreObject:Genre = genreArray[genreCount];
										if (genreObject != null) {
											
											var preferenceValue : int 	= genreObject.preferenceValue;
											var href:String   			= genreObject.href;
											
											if (genreObject.nameArray != null) {
												
												var genreNameCount : int = 0;
												for (genreNameCount = 0; genreNameCount < genreObject.nameArray.length; genreNameCount++) {

													if (genreObject.nameArray[genreNameCount] != null) {

														var genreNameType : NameType = genreObject.nameArray[genreNameCount]
														if (genreNameType != null) {

															var genreName :String = genreNameType.stringValue
															if (MetasoftULC.queryAll) {
																var childGenreArray:Array = MetasoftHelper.getCategoryChildren(genreName);
															} else {

																childGenreArray = new Array();
																childGenreArray.push(genreName);
															}
															for (var childCount:int = 0; childCount < childGenreArray.length; childCount ++){
											
																var genre:Genre = new Genre();
																genre = createGenre(preferenceValue,childGenreArray[childCount],href);
																classificationPreferencesType.genreArray.push(genre);
															}
														}
													}
												}
											}
										}
									}
									filteringAndSearchPreferencesType.classificationPreferencesArray.push(classificationPreferencesType);
//									userPreferencesObject.filteringAndSearchPreferencesArray.push(filteringAndSearchPreferencesType);
									
									if (genreArray == null ) { 
										continue; 
									}
									if (genreArray.length > 0 ) {
										existsAtleasetOne = true;
									}
									for(var k:int = 0; k < genreArray.length; k++) {
		
										var genreType:Genre = genreArray[k];
										if (genreType != null && genreType.nameArray[0] != null) {
		
											if (MetasoftULC.queryAll) {

												var genreSubArray:Array = MetasoftHelper.getCategoryChildren(genreType.nameArray[0].stringValue);
												var genreSubCount : int = 0;
												for (genreSubCount = 0; genreSubCount < genreSubArray.length; genreSubCount++) {

													binaryPredicate = createBinaryPredicate(MetasoftULC.Field_Genre, genreSubArray[genreSubCount], MetasoftULC.operator_Contains);
													classicpredicateBag.binaryPredicateArray.push(binaryPredicate);
												}
											} else if (MetasoftULC.Format_Movie == genreType.nameArray[0].name ||
												MetasoftULC.Format_Cinema == genreType.nameArray[0].name ) {
												
												binaryPredicate = createBinaryPredicate(MetasoftULC.Field_Genre,MetasoftULC.Format_Cinema,MetasoftULC.operator_Contains);
												predicateBag.predicateBagArray.push(binaryPredicate);
												isFormatCinema = true;
											} else {
				
												binaryPredicate = createBinaryPredicate(MetasoftULC.Field_Genre,genreType.nameArray[0].stringValue,MetasoftULC.operator_Contains);
												classicpredicateBag.binaryPredicateArray.push(binaryPredicate);
											}
										}
									}
								}
							}
							/*if (!isFormatCinema) {
		
								negatepredicateBag.contextNode = "ProgramInformation";
								negatepredicateBag.type = "OR";
								negatepredicateBag.negate = true;
								negatepredicateBag.binaryPredicateArray = new Array();
								binaryPredicate=createBinaryPredicate(MetasoftULC.Field_Genre, MetasoftULC.Format_Cinema, MetasoftULC.operator_Equals);
								negatepredicateBag.binaryPredicateArray.push(binaryPredicate);
								predicateBag.predicateBagArray.push(negatepredicateBag);
							}*/
							var creationPreferenceArray:Array = filteringAndSerachPref.creationPreferencesArray;
							if (creationPreferenceArray == null ) {
								
								if(classicpredicateBag != null && classicpredicateBag.binaryPredicateArray.length != 0) {
									predicateBag.predicateBagArray.push(classicpredicateBag);
								}
								continue;
							}
							if (classicpredicateBag ==null) {
		
								classicpredicateBag = new PredicateBagType();
//								classicpredicateBag.contextNode = "ProgramInformation";
								classicpredicateBag.type = "OR";
								classicpredicateBag.predicateBagArray = new Array();
								classicpredicateBag.binaryPredicateArray = new Array();
							}
							if (filteringAndSearchPreferencesType == null) {
								filteringAndSearchPreferencesType = new FilteringAndSearchPreferencesType();
							}
							filteringAndSearchPreferencesType.creationPreferencesArray = new Array()
							for (j = 0; j <creationPreferenceArray.length; j++) {
								
								var creationPref:CreationPreferencesType = creationPreferenceArray[j];
								var creatorArray: Array = creationPref.creatorArray;
								if (creatorArray == null ) {
									continue;
								}
								for(k = 0; k <creatorArray.length; k ++) {
		
									var creator:CreatorType = creatorArray[k];
									var nameArray:Array  = null;
									if (creator == null) { 
										continue; 
									}
									var role:ControlledTermUseType = creator.role;
									if (role == null || role.nameArray == null) {
										continue;
									}
									nameArray = role.nameArray;
									if (nameArray == null) { 
										continue; 
									}
									if (nameArray.length > 0 ) {
										existsAtleasetOne = true;
									}
									for(var l:int = 0; l <nameArray.length; l ++) {
		
										var name:NameType =nameArray[l];
										if (name == null || 
											name.stringValue == null || 
											name.stringValue  == "null" ||
											name.stringValue.length == 0) { 
												continue;
										}
										binaryPredicate = createBinaryPredicate(MetasoftULC.Field_CreditName, name.stringValue, MetasoftULC.operator_Equals);
										classicpredicateBag.binaryPredicateArray.push(binaryPredicate);
									}
								}
								if (filteringAndSearchPreferencesType == null) {
								filteringAndSearchPreferencesType = new FilteringAndSearchPreferencesType();
								}
								filteringAndSearchPreferencesType.creationPreferencesArray.push(creationPref);
							}
							if (userPreferencesObject.filteringAndSearchPreferencesArray == null ) {
								userPreferencesObject.filteringAndSearchPreferencesArray = new Array();
							}
							userPreferencesObject.filteringAndSearchPreferencesArray.push(filteringAndSearchPreferencesType);
							if (classicpredicateBag.binaryPredicateArray.length != 0)  {
								predicateBag.predicateBagArray.push(classicpredicateBag);
							}
						}
					}
				}
				if (userPreferences.userIdentifier != null
					&& userPreferences.userIdentifier.name != null) {

					var userIdentifierObj:UserIdentifierType = new UserIdentifierType();
					userIdentifierObj.name = new TextualType();
					userIdentifierObj.name.stringValue 	= userPreferences.userIdentifier.name.stringValue;
					userIdentifierObj.name.name			= userPreferences.userIdentifier.name.stringValue;
					userPreferencesObject.userIdentifier 	= userIdentifierObj;
				}
				personalInformation.userPreferences= userPreferencesObject;
			}
			if(usageHistoryType != null) {
				personalInformation.usageHistory =usageHistoryType;
			}
			if(userInformationTable != null) {
				personalInformation.userInformationTable = userInformationTable;
			}
			getDataType.personalInformation =personalInformation;
			if (!existsAtleasetOne) {

//				negatepredicateBag.contextNode = "ProgramInformation";
				negatepredicateBag.type = "OR";
				negatepredicateBag.negate = true;
				negatepredicateBag.binaryPredicateArray = new Array();
				binaryPredicate = createBinaryPredicate(MetasoftULC.Field_Genre, MetasoftULC.Format_Cinema, MetasoftULC.operator_Contains);
				//var newBinaryPredicate:BinaryPredicateType = createBinaryPredicate("Copyright", "Private", MetasoftULC.operator_Contains);
				//negatepredicateBag.binaryPredicateArray.push(newBinaryPredicate);
				negatepredicateBag.binaryPredicateArray.push(binaryPredicate);
				predicateBag.predicateBagArray.push(negatepredicateBag);
//				predicateBag.binaryPredicateArray =new Array();
//				predicateBag.binaryPredicateArray.push(binaryPredicate);
			}
			quesrConstraints.predicateBag = predicateBag;
			getDataType.queryConstraints = quesrConstraints;
			getDataType.maxPrograms =MetasoftULC.default_MAXPrograms;
			getDataDoc.getData = getDataType;
			return getDataDoc;
		}

		/**
		 * Convert CreditItem Object in to ArrayCollection 
		 * @param cInfo - CreditItems
		 * @return converted arraycollection object 
		 */
		public static function getCreditItemsFromProxy(creditsList:Object, product:Product):Array {

			if (creditsList == null) {
				return new Array();
			}
			if (creditsList.creditsItemArray == null) {
				return new Array();
			}
			var creditsListItems:Array = new Array();
			var aC:Array = new Array();
			if (creditsList.creditsItemArray != null && 
				creditsList.creditsItemArray is Array &&
				creditsList.creditsItemArray.length > 0) {
				creditsListItems = creditsList.creditsItemArray;
			}
			var objProxy:Object = new 	Object();
			for each(objProxy in creditsListItems) {
				
				var cItem:CreditItemInfo = new CreditItemInfo();
				if (objProxy.role != null) {

					var role :String = String(objProxy.role);
					cItem.role = role.substr(role.lastIndexOf(":") +1);
				}
				if (objProxy.personNameArray != null &&
					objProxy.personNameArray.length > 0) {

					if (objProxy.personNameArray[0] != null) {

						if (objProxy.personNameArray[0].givenNameArray[0] != null)
							cItem.fname = MetasoftUtils.getCData(String(objProxy.personNameArray[0].givenNameArray[0].stringValue));
						if (objProxy.personNameArray[0].familyNameArray[0] != null)
							cItem.lname = MetasoftUtils.getCData(String(objProxy.personNameArray[0].familyNameArray[0].stringValue));
					}
				}
				
				var creditorValue:String = cItem.role + ":" +  cItem.name;
				product.creditorArray.addItem(creditorValue);
				
				aC.push(cItem);
			}
			return aC;
		}		
		
		/**
		 * Convert CreditItem Object in to ArrayCollection 
		 * @param cInfo - CreditItems
		 */
		public static function getAwardItemsFromProxy(awardList:Object, product:Product):void {

			if (awardList == null) {
				return;
			}
			if (awardList.awardsListItemArray == null) {
				return;
			}
			var awardListItems:Array = new Array();

			if (awardList.awardsListItemArray != null && 
				awardList.awardsListItemArray is Array &&
				awardList.awardsListItemArray.length > 0) {
				awardListItems = awardList.awardsListItemArray;
			}
			
			var objProxy:Object = new 	Object();
			for each(objProxy in awardListItems) {
				
				var title:String = "";
				var recipient:String = "";
				if(objProxy.title !=null) {
					
					title = objProxy.title.stringValue; 	
				}
				
				if (objProxy.awardArray != null &&
					objProxy.awardArray.length > 0) {

					if (objProxy.awardArray[0] != null) {

						if (objProxy.awardArray[0].recipient != null &&
							objProxy.awardArray[0].recipient.personNameArray != null  && 
							objProxy.awardArray[0].recipient.personNameArray[0] != null) {
						 	
						 	if(objProxy.awardArray[0].recipient.personNameArray[0].givenNameArray != null && 
						 		objProxy.awardArray[0].recipient.personNameArray[0].givenNameArray[0] != null) {
						 			
						 		recipient = objProxy.awardArray[0].recipient.personNameArray[0].givenNameArray[0].stringValue;
						 	}
						 	
						 }
					}
				}
				
				if(title !="" && recipient !="") {
					var awardValue:String = title + ":" + recipient ;
					product.awardListArray.addItem(awardValue);
				}

			}
		}
		
		
		/**
		 * Convert ParentalGuidance Object into Array
		 * @param pgInfo - XMLList
		 * @return converted array object 
		 */
		public static function getParentalGuidanceFromProxy(proxy:Array):Array {
			
			var i:int = 0;
			if (proxy == null) return new Array();
			var pg:Array = new Array();
			for (i = 0; i < proxy.length; i++) {

				if (proxy[i] != null && proxy[i].parentalRating != null)
					pg.push(proxy[i].parentalRating.href);
			}
			return pg;
		}
		
       	/**
		 * Method to get the person profile data 
		 */
		public static function getPersonalProfile(userName:String, password:String):QueryDocument{


			var queryDoc:QueryDocument = new QueryDocument();
			var queryType : QueryType = new QueryType();
			var resourceID :ResourceIDType = new ResourceIDType();
			var queryItem : QueryItemType = new QueryItemType();
			var selectType : SelectType = new SelectType();
			selectType.type = "abbreviated";
			selectType.select = MetasoftULC.Profile_UserDescription;
			selectType.stringValue = MetasoftULC.Profile_UserDescription;
			queryItem.select = selectType;
			
			var serviceQueryItem : QueryItemType = new QueryItemType();
			var servicequeryItemSelectType : SelectType = new SelectType();
			servicequeryItemSelectType.type = "abbreviated";
			servicequeryItemSelectType.select = MetasoftULC.Req_Table_ServiceInformationTable;
			servicequeryItemSelectType.stringValue = MetasoftULC.Req_Table_ServiceInformationTable;
			serviceQueryItem.select = servicequeryItemSelectType;
			
			var grpQueryItem : QueryItemType = new QueryItemType();
			var grpqueryItemSelectType : SelectType = new SelectType();
			grpqueryItemSelectType.type = "abbreviated";
			grpqueryItemSelectType.select = MetasoftULC.Req_Table_GroupInformationTable;
			grpqueryItemSelectType.stringValue = MetasoftULC.Req_Table_GroupInformationTable;
			grpQueryItem.select = grpqueryItemSelectType;
			
			var pkgQueryItem : QueryItemType = new QueryItemType();
			var pkgqueryItemSelectType : SelectType = new SelectType();
			pkgqueryItemSelectType.type = "abbreviated";
			pkgqueryItemSelectType.select = MetasoftULC.Req_Table_PackageTable;
			pkgqueryItemSelectType.stringValue = MetasoftULC.Req_Table_PackageTable;
			pkgQueryItem.select = pkgqueryItemSelectType;
			
			var targetQueryItem : QueryItemType = new QueryItemType();
			var targetqueryItemSelectType : SelectType = new SelectType();
			targetqueryItemSelectType.type = "abbreviated";
			targetqueryItemSelectType.select = MetasoftULC.Req_Table_TargetingInformationTable;
			targetqueryItemSelectType.stringValue = MetasoftULC.Req_Table_TargetingInformationTable;
			targetQueryItem.select = targetqueryItemSelectType;
			
			resourceID.id = MetasoftUtils.buildCredentials(userName,password);
			queryType.resourceID = resourceID;
			queryType.queryItemArray = new Array();
			queryType.queryItemArray.push(queryItem);
			queryType.queryItemArray.push(serviceQueryItem);
			queryType.queryItemArray.push(grpQueryItem);
			queryType.queryItemArray.push(pkgQueryItem);
			queryType.queryItemArray.push(targetQueryItem);
			queryDoc.query=queryType;
			return queryDoc;
		}
		
		public static function getPackageQueryDocument(userName:String):QueryDocument
		{
			var queryDoc:QueryDocument = new QueryDocument();
			var queryType : QueryType = new QueryType();
			var resourceID :ResourceIDType = new ResourceIDType();
			var pkgQueryItem : QueryItemType = new QueryItemType();
			var pkgqueryItemSelectType : SelectType = new SelectType();
			pkgqueryItemSelectType.type = "abbreviated";
			pkgqueryItemSelectType.select = MetasoftULC.Req_Table_PackageTable;
			pkgqueryItemSelectType.stringValue = MetasoftULC.Req_Table_PackageTable;
			pkgQueryItem.select = pkgqueryItemSelectType;
			resourceID.id = MetasoftUtils.buildCredentials(userName,userName);
			queryType.resourceID = resourceID;
			queryType.queryItemArray = new Array();
			queryType.queryItemArray.push(pkgQueryItem);
			queryDoc.query=queryType;
			return queryDoc;
		}
		
		/**
		 * Method to process the userPreference returned from getPersonalProfile service and 
		 * store it in the shared object's profileInfo
		 * */
		public static function processUserPreference(profileInfo:ProfileInfo, userPreferences:Object) : UserPreferencesType {
			
			var userPreferencesType : UserPreferencesType = null;
			var i:int = 0;
			
			if (userPreferences != null && userPreferences.userIdentifier != null && userPreferences.userIdentifier.name != null) {

				userPreferencesType = new UserPreferencesType();
				userPreferencesType.userIdentifier = new UserIdentifierType();
				userPreferencesType.userIdentifier.name = new TextualType();
				userPreferencesType.userIdentifier.name.stringValue = userPreferences.userIdentifier.name.stringValue;
				userPreferencesType.userIdentifier.name.name		= userPreferences.userIdentifier.name.stringValue;
			}
			if (userPreferences != null && userPreferences.filteringAndSearchPreferencesArray != null && 
				userPreferences.filteringAndSearchPreferencesArray.length > 0) {

				if (userPreferences.filteringAndSearchPreferencesArray[0] != null) {

		        	var classificationPreferences:Object = userPreferences.filteringAndSearchPreferencesArray[0].classificationPreferencesArray[0];
		        	var creationPreferences:Object = userPreferences.filteringAndSearchPreferencesArray[0].creationPreferencesArray[0];
	
		        	if (classificationPreferences != null) {
			        		
			        	if (userPreferencesType == null) {
			        		userPreferencesType = new UserPreferencesType();
			        	}
			        	userPreferencesType.filteringAndSearchPreferencesArray = new Array();
						var filteringAndSerachPref:FilteringAndSearchPreferencesType = new FilteringAndSearchPreferencesType();
						var childGenreArray:Array =  null;
			        	if (classificationPreferences.genreArray != null && 
			        		classificationPreferences.genreArray.length > 0) {
		
			        		filteringAndSerachPref.classificationPreferencesArray = new Array();
			        		var classificationPref:ClassificationPreferencesType = new ClassificationPreferencesType();
			        		classificationPref.genreArray = new Array();
			        		var genreObj:Array = classificationPreferences.genreArray;
			        		profileInfo.atmosphere = new Array();
			        		profileInfo.audience = new Array();
			        		profileInfo.content = new Array();
			        		profileInfo.intention = new Array();
			        		profileInfo.format = null;
			        		var childCount:int = 0;
			        		if (genreObj != null && genreObj is Array) {
			        			processGenreTypes(genreObj, classificationPref, profileInfo);
			        		}
			        		filteringAndSerachPref.classificationPreferencesArray.push(classificationPref);
			        	}
		        	}
		        	
		        	if (creationPreferences != null) {
	
		        		filteringAndSerachPref.creationPreferencesArray = new Array();
		        		var creationPreferencesType:CreationPreferencesType = new CreationPreferencesType();
		        		creationPreferencesType.creatorArray = new Array();

//		        		var creatorType: Creator  = new Creator();
//		        		var personNameType:PersonNameType = new PersonNameType();
//						var gN:NameComponentType = new NameComponentType;
//						gN.givenName = profileInfo.userId;
//						gN.stringValue = profileInfo.userId;
//						personNameType.givenNameArray = new Array();
//						personNameType.givenNameArray.push(gN);
//						creatorType.characterArray  = new Array();
//						creatorType.characterArray.push(personNameType);

//						var creatorType: Creator  = new Creator();
//						creatorType.role = new ControlledTermUseType();
//						creatorType.role.nameArray = new Array();
						
		        		profileInfo.creditNames = new Array();
		        		var creatorObj:Object = creationPreferences.creatorArray;
		        		
		        		if (creatorObj != null) {
	
			        		var creator :Object = null;
			        		var rolObjProxy:Object = null;
			        		var perfValue:int = 0;
			        			for(i = 0; i < creatorObj.length; i++){
		
									perfValue = creatorObj[i].preferenceValue;
									if (creatorObj[i].role != null && creatorObj[i].role.nameArray != null && creatorObj[i].role.nameArray.length > 0) {

										for(var j:int = 0; j < creatorObj[i].role.nameArray.length; j++){
		
			        						var creatorRole:Object = Object(creatorObj[i].role.nameArray[j]);
			        						if (creatorRole != null){

			        							if (creatorRole.stringValue != null) {
		
													var creatorType: Creator  = new Creator();
													creatorType.role = new ControlledTermUseType();
													creatorType.role.nameArray = new Array();
							        				var name:NameType = new NameType();
							        				profileInfo.creditNames[String(creatorRole.stringValue)] = perfValue ;
													name.stringValue = String(creatorRole.stringValue);
													creatorType.role.nameArray.push(name);
													creatorType.preferenceValue = perfValue;
							        			}
			        						}
			        						creationPreferencesType.creatorArray.push(creatorType);
			        					}
									}
			        			}
			        		filteringAndSerachPref.creationPreferencesArray.push(creationPreferencesType);
			        	}
		        	}
		        	userPreferencesType.filteringAndSearchPreferencesArray.push(filteringAndSerachPref);
	  			}
	  		}
  			return userPreferencesType;
		}
	
	/**
	 * Method to get the modify personal Info for the user
	 */
	public static function modifyPersonalProfile(profileInfo:ProfileInfo):ModifyDocument {
		
		var userId :String 		= profileInfo.userId;
		var password:String 	= profileInfo.password;
		var oldpassword:String 	= profileInfo.oldPassword;
		var contentArray:Array 	= profileInfo.content;
		var atmosphereArray:Array 	= profileInfo.atmosphere;
		var audienceArray:Array 	= profileInfo.audience;
		var intentionArray:Array 	= profileInfo.intention;
		var format:String 			= profileInfo.format;
		var creditNamesArray:Array 	= profileInfo.creditNames;
		var usageHistory:UsageHistoryType 	= profileInfo.usageHistory;			
		var modify:ModifyType 				= new ModifyType();
		var resourceID:ResourceIDType 		= new ResourceIDType();
		var modification:Modification	 	= new Modification();
		var selectType:SelectType 			= new SelectType();
		selectType.type 	= "abbreviated";
		selectType.select 	= MetasoftULC.Profile_UserDescription;
		selectType.stringValue 	= MetasoftULC.Profile_UserDescription;
		resourceID.resourceID 	= "http://profile-provider.com/d8ddw6dd7m28v628";
		resourceID.id 		= MetasoftUtils.buildCredentials(userId, password);
		modify.resourceID 	= resourceID;
		modification.select = selectType;
		modification.itemID = MetasoftULC.Profile_UserDescription;
		var newData:NewData  			=  new NewData();
		var tvaMain:ExtendedTVAMainType = new ExtendedTVAMainType();

		var userPreferencesType : UserPreferencesType = processUserPreferenceAfterUpdate(profileInfo);
		userPreferencesType.userIdentifier 		= new UserIdentifierType();
		userPreferencesType.userIdentifier.name = new TextualType();
		userPreferencesType.userIdentifier.name.stringValue = userId;
		var userDescription:UserDescriptionType = new UserDescriptionType();
		userDescription.userPreferences = userPreferencesType;
		tvaMain.userDescriptionArray 	= new Array;
		tvaMain.userDescriptionArray.push(userDescription);
		
		var targetingInformationTable:TargetingInformationTableType = new TargetingInformationTableType();
		var targetingInformation:TargetingInformationType = new TargetingInformationType();
		var userInformation:UserInformationType = new UserInformationType();
		var biographicInformation:BiographicInformationType = new BiographicInformationType();
		biographicInformation.age = Number(profileInfo.age);
		biographicInformation.gender = profileInfo.gender;
		var personNameType:PersonNameType = new PersonNameType();
		var gN:NameComponentType = new NameComponentType;
		gN.givenName = profileInfo.userId;
		gN.stringValue = profileInfo.userId;
		personNameType.givenNameArray = new Array();
		personNameType.givenNameArray.push(gN);
		var lN:NameComponentType = new NameComponentType;
		lN.linkingName = profileInfo.password;
		lN.stringValue = profileInfo.password;
		personNameType.linkingNameArray = new Array();
		personNameType.linkingNameArray.push(lN);
		var fN:NameComponentType = new NameComponentType;
		fN.familyName = profileInfo.userId;
		fN.stringValue = profileInfo.userId;
		personNameType.familyNameArray = new Array();
		personNameType.familyNameArray.push(fN);
		biographicInformation.nameArray = new Array();
		biographicInformation.nameArray.push(personNameType);
		userInformation.biographicInformationArray = new Array();
		userInformation.biographicInformationArray.push(biographicInformation);
		targetingInformation.userInformationArray = new Array();
		targetingInformation.userInformationArray.push(userInformation);
		targetingInformationTable.targetingInformationArray = new Array();
		targetingInformationTable.targetingInformationArray.push(targetingInformation);
		tvaMain.targetingInformationTable = targetingInformationTable;

		newData.TVAMain 			= tvaMain;
		modification.newData		= newData;
		modify.modificationArray 	= new Array();
		modify.modificationArray.push(modification);
		var modifyDoc:ModifyDocument = new ModifyDocument();
		modifyDoc.modify = modify;
		return modifyDoc;
	}
	
	/**
	 * Method to get the modify personal Info for the user
	 * */
	public static function modifyUsageHistory(profileInfo:ProfileInfo):ModifyDocument {
		
		var userId :String 			= profileInfo.userId;
		var password:String 		= profileInfo.password;
		var oldpassword:String 		= profileInfo.oldPassword;
		var credentialInfo:String 	= MetasoftUtils.buildCredentials(userId,oldpassword);
		var url:String 				= "http://profile-provider.com/";
		var usageHistory:UsageHistoryType 	= profileInfo.usageHistory;
		var modify:ModifyType 				= new ModifyType();
		var modification:Modification	 	= new Modification();
		var selectType:SelectType 			= new SelectType();
		var resourceID:ResourceIDType 		= new ResourceIDType();
		selectType.type 		= "abbreviated";
		selectType.select 		= MetasoftULC.Profile_UserDescription;
		selectType.stringValue 	= MetasoftULC.Profile_UserDescription;
		modification.select 	= selectType;
		modification.itemID 	= MetasoftULC.Profile_UserDescription;
		resourceID.resourceID 	= url;
		resourceID.id 			= MetasoftUtils.buildCredentials(userId, password);
		modify.resourceID 		= resourceID;

		if (usageHistory != null) {

			var newData:NewData  					= new NewData();
			var tvaMain:ExtendedTVAMainType 		= new ExtendedTVAMainType();
			var userDescription:UserDescriptionType = new UserDescriptionType();
			var usageHistoryObj : UsageHistoryType 	= new UsageHistoryType();
			usageHistoryObj.userIdentifier 			= new UserIdentifierType();
			usageHistoryObj.userIdentifier.name		= new TextualType();
			usageHistoryObj.userIdentifier.name.stringValue = userId;
			usageHistoryObj.userActionHistoryArray 	= usageHistory.userActionHistoryArray;
		
			if (usageHistory.userActionHistoryArray != null &&
				usageHistory.userActionHistoryArray.length > 0) {

				usageHistoryObj.userActionHistoryArray = new Array();
				var userActionHistory : UserActionHistoryType = usageHistory.userActionHistoryArray[0];
				if (userActionHistory != null) {

					var userActionHistoryObj :UserActionHistoryType = new UserActionHistoryType();
					var observationPeriodArray : Array = userActionHistory.observationPeriodArray;
					if (observationPeriodArray != null &&
						observationPeriodArray.length > 0) {

						userActionHistoryObj.observationPeriodArray = new Array();
						var observationPeriod : TimeType  = observationPeriodArray[0];
						if (observationPeriod != null) {
							
							var observationPeriodObj : TimeType  = new TimeType();
							observationPeriodObj.timePoint = observationPeriod.timePoint;
							userActionHistoryObj.observationPeriodArray.push(observationPeriodObj);
						}
					}
					var userActionListArray : Array = userActionHistory.userActionListArray;
					if (userActionListArray != null &&
						userActionListArray.length > 0) {

						userActionHistoryObj.userActionListArray = new Array();
					 	for(var i:int = 0; i < userActionListArray.length; i++) {

							var userActionListObj:UserActionListType	= new UserActionListType();
							var userActionListType: UserActionListType  = userActionListArray[i];
							if (userActionListType != null) {

								var actionType:TermUseType 	= userActionListType.actionType;
								if (actionType != null) {

									var actionTypeNameArray :Array 	= actionType.nameArray;
									if (actionTypeNameArray != null && 
										actionTypeNameArray.length > 0) {

										var nameType:NameType = actionTypeNameArray[0];
										if (nameType != null) {

											var actionTypeObj:TermUseType = new TermUseType();
											var nameTypeObj:NameType 	= new NameType();
											nameTypeObj.name 		= nameType.name;
											nameTypeObj.stringValue = nameType.name;
											actionTypeObj.nameArray = new Array();
											actionTypeObj.nameArray.push(nameTypeObj);
											userActionListObj.actionType = actionTypeObj;
										}
									}
								}
								var userActionArray : Array 	= userActionListType.userActionArray;
								userActionListObj.userActionArray = new Array();
								for(var j:int = 0; j < userActionArray.length; j++) {

									var userActionObj:UserActionType = new UserActionType();
									if (userActionArray[j] != null) {

										var userActionType : UserActionType = userActionArray[j];
										if (userActionType != null) {

											var actionTime : UserActionType_ActionTime = userActionType.actionTime;
											if (actionTime != null) { 
		
												userActionObj.actionTime = new UserActionType_ActionTime();
												if (actionTime.generalTime != null) {
		
													userActionObj.actionTime.generalTime = new TimeType();
													if (actionTime.generalTime.timePoint != null) {
														userActionObj.actionTime.generalTime.timePoint = actionTime.generalTime.timePoint;
													}
													if (actionTime.generalTime.duration != null) {
														userActionObj.actionTime.generalTime.duration = actionTime.generalTime.duration;
													}
													userActionObj.actionTime.generalTime = actionTime.generalTime;
												}
											}
											var uniqueIdType : UniqueIDType = userActionType.programIdentifier;
											userActionObj.programIdentifier = new UniqueIDType(); 
											if (uniqueIdType != null) {
						
												userActionObj.programIdentifier.type 			= uniqueIdType.type;
												userActionObj.programIdentifier.encoding 		= uniqueIdType.encoding;
												userActionObj.programIdentifier.organization 	= uniqueIdType.organization;
												userActionObj.programIdentifier.value 			= uniqueIdType.organization;
												userActionObj.programIdentifier.stringValue 	= uniqueIdType.organization;
											}
										}
									}
									userActionListObj.userActionArray.push(userActionObj);
								}
								userActionListObj.numOfInstances = userActionListArray.length;
							}
							userActionHistoryObj.userActionListArray.push(userActionListObj);
						}
					}
					usageHistoryObj.userActionHistoryArray.push(userActionHistoryObj);
				}
			}
			userDescription.usageHistory = usageHistoryObj;
			tvaMain.userDescriptionArray = new Array;
			tvaMain.userDescriptionArray.push(userDescription);
			newData.TVAMain 			= tvaMain;
			modification.newData		= newData;
			modify.modificationArray 	= new Array();
			modify.modificationArray.push(modification);
			var modifyDoc:ModifyDocument = new ModifyDocument();
			modifyDoc.modify = modify;
		}
		return modifyDoc;
	}
	
	/**
	 * method to get the genre xml as string for modify data
	 * */ 
	public static function formGenreQuery(name:String,genreArray:Array):String {
		var request:String = "";
		if(genreArray != null){
			 for (var genreName:String in genreArray) {
				var genrePref:Object = genreArray[genreName];
				var genrePrefNumValue:Number = Number(genrePref);
				if(isNaN(genrePrefNumValue)) 
					genrePrefNumValue = MetasoftULC.default_PrefValue;
				if (genrePrefNumValue != 0){
					request = request.concat("<urn2:Genre href=\"" + name + ":\" preferenceValue=\""+ genrePref + "\">")
					 			.concat("<urn2:Name preferred=\"true\">" + genreName + "</urn2:Name></urn2:Genre>");
				}
			 }
		}
		return request;
	}
	
	/**
	 * Method to process the userPreference returned from getPersonalProfile service and 
	 * store it in the shared object's profileInfo
	 * */
	public static function processUserPreferenceAfterUpdate(profileInfo:ProfileInfo) : UserPreferencesType{
		
		var userPreferencesType : UserPreferencesType = null;
		var i:int = 0;
		if (profileInfo != null){

        	userPreferencesType = new UserPreferencesType();
			var so:SharedObject = SharedObject.getLocal(MetasoftULC.LoggedInUser);
			if (so != null && so.data != null && so.data.preference != null && so.data.preference.userIdentifier != null) {

				userPreferencesType.userIdentifier = new UserIdentifierType();
				userPreferencesType.userIdentifier.name = new TextualType();
				userPreferencesType.userIdentifier.name.stringValue = so.data.preference.userIdentifier.name.stringValue;
				userPreferencesType.userIdentifier.name.name 		= so.data.preference.userIdentifier.name.stringValue;
			}
        	userPreferencesType.filteringAndSearchPreferencesArray = new Array();
			var filteringAndSerachPref:FilteringAndSearchPreferencesType = new FilteringAndSearchPreferencesType();
        	var atmosphereArray:Array = profileInfo.atmosphere;
        	var audienceArray:Array = profileInfo.audience;
        	var contentArray:Array = profileInfo.content;
        	var intentionArray:Array = profileInfo.intention;
        	var format:String = profileInfo.format;
        	var creditNamesArray:Array = profileInfo.creditNames;
        	
        	var formatArray:Array = new Array();
        	if (format != null && 
        		(MetasoftULC.Format_Cinema == format || MetasoftULC.Format_Movie == format)) {
        		formatArray[MetasoftULC.Format_Cinema] = MetasoftULC.default_PrefValue;
        	}
        	if (atmosphereArray != null || 
        		audienceArray != null || 
        		contentArray != null || 
        		intentionArray != null)  {

        		filteringAndSerachPref.classificationPreferencesArray = new Array();
        		var classificationPref:ClassificationPreferencesType = new ClassificationPreferencesType();
        		classificationPref.genreArray = new Array();
        		processGenreTypesAfterUpdate(atmosphereArray,classificationPref,MetasoftULC.CS_Atmosphere);
        		processGenreTypesAfterUpdate(audienceArray,classificationPref,MetasoftULC.CS_IntendedAudience);
        		processGenreTypesAfterUpdate(contentArray,classificationPref,MetasoftULC.CS_Content);
        		processGenreTypesAfterUpdate(intentionArray,classificationPref,MetasoftULC.CS_Intention);
        		processGenreTypesAfterUpdate(formatArray,classificationPref,MetasoftULC.CS_Format);
        		filteringAndSerachPref.classificationPreferencesArray.push(classificationPref);
        	}
        	
        	if (creditNamesArray != null) {

        		filteringAndSerachPref.creationPreferencesArray = new Array();
        		var creationPreferencesType:CreationPreferencesType = new CreationPreferencesType();
				creationPreferencesType.creatorArray = new Array();

    			for (var creditName:String in creditNamesArray) {

					var creditPref:Object = creditNamesArray[creditName];
					var creditPrefNumValue:Number = Number(creditPref);
					if(isNaN(creditPrefNumValue)) { 
						creditPrefNumValue = MetasoftULC.default_PrefValue;
					}
					if (creditPrefNumValue != 0) {

//        				var creatorType: Creator  = new Creator();
//						var personNameType:PersonNameType = new PersonNameType();
//						var gN:NameComponentType = new NameComponentType;
//						gN.givenName = profileInfo.userId;
//						gN.stringValue = profileInfo.userId;
//						personNameType.givenNameArray = new Array();
//						personNameType.givenNameArray.push(gN);
//						creatorType.characterArray  = new Array();
//						creatorType.characterArray.push(personNameType);
						var creatorType: Creator  = new Creator();
						creatorType.role = new ControlledTermUseType();
						creatorType.role.nameArray = new Array();
						var name:NameType = new NameType();
						name.stringValue = creditName;
						creatorType.role.nameArray.push(name);
						
        				creatorType.preferenceValue = creditPrefNumValue;

        				creationPreferencesType.creatorArray.push(creatorType);
					}
		 		}
        		filteringAndSerachPref.creationPreferencesArray.push(creationPreferencesType);
        	}
        	userPreferencesType.filteringAndSearchPreferencesArray.push(filteringAndSerachPref);
	  	}
  		return userPreferencesType;
	}
	
	/**
	 * Creates and returns a binary predicate for the given attribute values
	 */
	public static function createBinaryPredicate(fieldId:String, fieldValue:String, testValue:String):BinaryPredicateType {
			
		var binaryPredicate:BinaryPredicateType = new BinaryPredicateType();
		binaryPredicate.fieldID 	= fieldId;
		binaryPredicate.fieldValue 	= fieldValue;
		binaryPredicate.test 		= testValue;
		return binaryPredicate;
	}

	/**
	 * Creates and returns a Genre for the given attribute values
	 */
	public static function createGenre(prefValue:int, genreName:String, href:String):Genre {
			
		var genreType:Genre = new Genre();
		var nameType:NameType = new NameType();
		nameType.stringValue = genreName;
		genreType.nameArray = new Array();
		genreType.nameArray.push(nameType);
		genreType.preferenceValue = prefValue;
		genreType.href = href;

		return genreType;
	}

	/**
	 * Method to process the genretypes for retaining the userpreference
	 * */
	public static function processGenreTypes(genreArray:Array, classificationPref:ClassificationPreferencesType, profileInfo:ProfileInfo):void {

		if (genreArray == null) return;
		var genreType:Genre = null
		for(var i:int = 0; i < genreArray.length; i++){

			var genre:Object  = Object(genreArray[i]);
			var href:String   = String(genre.href);
			var genreName : String = new String(); 
			if (genre.nameArray[0] != null) {
				genreName = String(genre.nameArray[0].stringValue);
			}
			var preferenceValue :int = int(genre.preferenceValue);
			if (href.indexOf(MetasoftULC.CS_Atmosphere) != -1){
				profileInfo.atmosphere[genreName] = preferenceValue;
			}else if (href.indexOf(MetasoftULC.CS_Content) != -1){
				profileInfo.content[genreName] = preferenceValue;
			}else if (href.indexOf(MetasoftULC.CS_Format) != -1){
				profileInfo.format = genreName;
			}else if (href.indexOf(MetasoftULC.CS_IntendedAudience) != -1){
				profileInfo.audience[genreName] = preferenceValue;
			}else if (href.indexOf(MetasoftULC.CS_Intention) != -1){
				profileInfo.intention[genreName] = preferenceValue;
			}
			genreType = createGenre(preferenceValue, genreName, href);
			classificationPref.genreArray.push(genreType);
			/*if (MetasoftULC.queryAll){

				var childGenreArray:Array = MetasoftHelper.getCategoryChildren(genreName);
				for (var childCount:int = 0; childCount < childGenreArray.length; childCount ++){

					genreType = createGenre(preferenceValue,childGenreArray[childCount],href);
					classificationPref.genreArray.push(genreType);
				}
			} else {
				
				genreType = createGenre(preferenceValue, genreName, href);
				classificationPref.genreArray.push(genreType);
			}*/
		}
	}
	
	/**
	 * Method to process the genretypes after modification for retaining the userpreference
	 * */
	public static function processGenreTypesAfterUpdate(genreArray:Array, classificationPref:ClassificationPreferencesType, genreTypeHref : String):void{

		if (genreArray == null) {
			return;
		}
		var genreType:Genre = new Genre();
		for (var genreName:String in genreArray) {

			var genrePref:String = genreArray[genreName];
			genreType = createGenre(int(genrePref),genreName, genreTypeHref);
			classificationPref.genreArray.push(genreType);
			/*if (MetasoftULC.queryAll) {

				var childGenreArray:Array = MetasoftHelper.getCategoryChildren(genreName);
				for (var childCount:int = 0; childCount < childGenreArray.length; childCount ++){

					genreType = createGenre(int(genrePref),childGenreArray[childCount], genreTypeHref);
					classificationPref.genreArray.push(genreType);
				}
			} else {
				genreType = createGenre(int(genrePref),genreName, genreTypeHref);
				classificationPref.genreArray.push(genreType);
			}*/
		}
	}
	
	/**
	 * Method to gather UsageHistory
	 * */
	public static function retrieveAndStoreUsageHistory(program:ProgramItem):void{
		
		if (program == null) {
			return;
		}
		var so:SharedObject 		= SharedObject.getLocal(MetasoftULC.LoggedInUser);
		var profileInfo:ProfileInfo = so.data.profileInfo;
		var usageHistory: UsageHistoryType 		= profileInfo.usageHistory;
		var userIdentifier : UserIdentifierType = null;
		var name:TextualType  = null;
		var userActionHistory : UserActionHistoryType  = null;
		var observationPeriod :TimeType = null;
		var formatter:DateFormatter  	= null;
		var userActionListType: UserActionListType = null;
		var actionType:TermUseType  = null;	
		var nameType:NameType  		= null;
		var userActionType :UserActionType  = null;
		var uniqueIdType :UniqueIDType  	= null;
		var usageHistoryModified : Boolean 	= false;
		formatter  = new DateFormatter();
		formatter.formatString 		= MetasoftULC.default_dateFormat;
		var currDateString:String 	= formatter.format(new Date());
		var actionTime : UserActionType_ActionTime = new UserActionType_ActionTime();
		var generalTime : TimeType 	= new TimeType();
		var duration : String = MetasoftULC.default_duration;
		
		if (usageHistory == null ||
			usageHistory.userActionHistoryArray == null) {

			usageHistory 	= new UsageHistoryType();
			userIdentifier  = new UserIdentifierType();
			name  			= new TextualType();
			userActionHistory  = new UserActionHistoryType();
			observationPeriod  = new TimeType();
			userActionListType = new UserActionListType();
			actionType 	= new TermUseType();			
			nameType 	= new NameType();
			userActionType  = new UserActionType();
			actionTime 		= new UserActionType_ActionTime();
			generalTime 	= new TimeType();
			generalTime.timePoint 		= currDateString;
			generalTime.duration 		= duration;
			actionTime.generalTime 		= generalTime;
			userActionType.actionTime 	= actionTime;
			uniqueIdType = new UniqueIDType();
			uniqueIdType.organization 	= program.id;
			uniqueIdType.stringValue	= program.id;
			uniqueIdType.value	= program.id;
			userActionType.programIdentifier = uniqueIdType;
			nameType.name = retriveActionType(program.preview);
			nameType.stringValue = retriveActionType(program.preview);
			actionType.nameArray = new Array();
			actionType.nameArray.push(nameType);
			userActionListType.userActionArray = new Array();
			userActionListType.userActionArray.push(userActionType);
			userActionListType.actionType = actionType;
			userActionListType.numOfInstances = userActionListType.userActionArray.length;
			userActionHistory.userActionListArray = new Array();
			userActionHistory.userActionListArray.push(userActionListType);
			observationPeriod.timePoint = currDateString;
			userActionHistory.observationPeriodArray = new Array();
			userActionHistory.observationPeriodArray.push(observationPeriod);
			usageHistory.userActionHistoryArray = new Array();
			usageHistory.userActionHistoryArray.push(userActionHistory);
			name.name = profileInfo.userId;
			userIdentifier.name = name;
			userIdentifier.name.stringValue = profileInfo.userId;
			usageHistory.userIdentifier = userIdentifier;
			usageHistoryModified = true;
		} else if (usageHistory != null && 
			usageHistory.userActionHistoryArray != null) {

			var userActionHistoryArray : Array = usageHistory.userActionHistoryArray;
			userActionHistory = userActionHistoryArray[0];
			var userActionListArray : Array = userActionHistory.userActionListArray;
			var isNewActionType :Boolean = true;
			for(var userActionListArrayCount :int=0; userActionListArrayCount < userActionListArray.length; userActionListArrayCount++){

				userActionListType = userActionListArray[userActionListArrayCount];
				actionType = userActionListType.actionType;
				var userActionArray : Array = userActionListType.userActionArray;
				var actionTypeNameArray :Array = actionType.nameArray;
				nameType = actionTypeNameArray[0];
				var actionTypeNameStr :String = nameType.name;
				var newActionTypeNameStr : String = retriveActionType(program.preview);
				if (actionTypeNameStr == newActionTypeNameStr){

					isNewActionType = false;
					break;
				}
			} 
			if (isNewActionType){

				userActionType = new UserActionType();
				actionTime = new UserActionType_ActionTime();
				generalTime = new TimeType();
				generalTime.timePoint = currDateString;
				generalTime.duration = duration;
				actionTime.generalTime = generalTime;
				userActionType.actionTime = actionTime;
				
				userActionType.timeBase = "T" + currDateString + "Z"; 
				uniqueIdType = new UniqueIDType();
				uniqueIdType.organization 	= program.id;
				uniqueIdType.stringValue   	= program.id;
				uniqueIdType.value   		= program.id;
				userActionType.programIdentifier = uniqueIdType;
				userActionListType = new UserActionListType();
				userActionListType.userActionArray = new Array();
				userActionListType.userActionArray.push(userActionType);
				userActionListType.numOfInstances = userActionListType.userActionArray.length;
				nameType = new NameType();
				nameType.name 			= newActionTypeNameStr;
				nameType.stringValue 	= newActionTypeNameStr;
				actionType 				= new TermUseType();
				actionType.nameArray 	= new Array();
				actionType.nameArray.push(nameType);
				userActionListType.actionType = actionType;
				userActionListArray.push(userActionListType);
				userActionHistory.userActionListArray = userActionListArray;
				usageHistory.userActionHistoryArray = userActionHistoryArray;
				usageHistoryModified = true;
			} else {

				var isExistingUserAction :Boolean = false;
				for(var userActionCount:int = 0; userActionCount < userActionListType.userActionArray.length; userActionCount++) {

					var existingUserActionType : UserActionType = userActionListType.userActionArray[userActionCount];
					if (program.id == existingUserActionType.programIdentifier.organization){

						isExistingUserAction = true;
						break;
					}
				}
				if (!isExistingUserAction) {

					userActionType = new UserActionType();
					actionTime = new UserActionType_ActionTime();
					generalTime = new TimeType();
					generalTime.timePoint = currDateString;
					generalTime.duration = duration;
					actionTime.generalTime = generalTime;
					userActionType.actionTime = actionTime;
					userActionType.timeBase = "T" + currDateString + "Z"; 
					uniqueIdType = new UniqueIDType();
					uniqueIdType.organization  	= program.id;
					uniqueIdType.stringValue   	= program.id;
					uniqueIdType.value   		= program.id;
					userActionType.programIdentifier = uniqueIdType;
					userActionListType.userActionArray.push(userActionType);
					userActionListType.numOfInstances = userActionListType.userActionArray.length;
					userActionHistory.userActionListArray = userActionListArray;
					usageHistory.userActionHistoryArray = userActionHistoryArray;
					usageHistoryModified = true;
				}
			}
		}
		if (usageHistoryModified){

			profileInfo.usageHistory 	= usageHistory;
			so.data.profileInfo 		= profileInfo;
			var server:MetasoftServer 	= new MetasoftServer();
			server.modifyUsageHistory(profileInfo);
		}
	}
	
		/**
		 * Method to get the action type of 
		 * */
		public static function retriveActionType(preview:String):String{
			if (preview == null) return "Preview";
			for(var i:int = 0; i < MetasoftULC.Type_Images.length; i++){
				if (preview.lastIndexOf(MetasoftULC.Type_Images[i]) != -1){
					return "Preview";
				}
			}
			return "Video";
		}
		
		
		/**
		 * Method to process the usageHistory returned from getPersonalProfile service and 
		 * store it in the shared object's profileInfo
		 * 
		 */
		public static function processUsageHistory(usageHistory:Object) : UsageHistoryType {
			
	  		var usageHistoryType : UsageHistoryType = null;
			var userIdentifier : UserIdentifierType = null;
			var name:TextualType = null;
			var userActionHistoryType : UserActionHistoryType = null;
			var timeType :TimeType =  null;
			var formatter:DateFormatter = null;
			var userActionListType: UserActionListType = null;
			var termUseType:TermUseType = null;
	  		var nameType:NameType = null;
			var userActionType :UserActionType = null;
			var uniqueIdType :UniqueIDType = null;
			var actionTime : UserActionType_ActionTime = null;
			
	  		if (usageHistory != null){
	  			usageHistoryType = new UsageHistoryType();
	    		var userActionHistory: Object = usageHistory.userActionHistoryArray;
	    		var userIdentifierObj: Object = usageHistory.userIdentifier;
	    		
	    		if (userActionHistory != null && 
	    			userActionHistory.length > 0 &&
	    			userActionHistory[0] != null){

	    			var userActionObj : Object = null;
	    			var programIdentifier : Object= null;
	    			var generalTimeObj : Object = null;
	    			var durationStr : String = null;
	    			var timePointStr : String = null;
	    			var actionTimeObj : Object= null;
	    			 
	    			usageHistoryType.userActionHistoryArray = new Array();
	    			userActionHistoryType  = new UserActionHistoryType();
	    			var observationPeriod :Object = userActionHistory[0].observationPeriodArray;
	    			if (observationPeriod != null &&
	    				observationPeriod.length > 0 &&
	    				observationPeriod[0] != null){

	    				userActionHistoryType.observationPeriodArray = new Array();
	    				var timePointObj :String = observationPeriod[0].timePoint;
	    				if (timePointObj != null){

	    					timeType = new TimeType();
							formatter = new DateFormatter();
							formatter.formatString = MetasoftULC.default_dateFormat;
							timeType.timePoint = formatter.format(timePointObj);
							userActionHistoryType.observationPeriodArray.push(timeType);
	    				}
	    			}
	    			
	    			var userActionListObj : Object = userActionHistory[0].userActionListArray;
	    			var userActionList : Object;
	    			if (userActionListObj != null && 
	    				userActionListObj.length > 0) {

	    				userActionHistoryType.userActionListArray = new Array();
	        			for(var userActionListCount :int = 0; userActionListCount < userActionListObj.length; userActionListCount++){

		        			userActionList = Object(userActionListObj[userActionListCount]);
		        			if (userActionList != null){

		        				userActionListType = new UserActionListType();
		        				var noObject : Object = userActionList.numOfInstances;
		        				if ( noObject != null && !isNaN(Number(noObject))){

		        					var no:Number = Number(userActionList.numOfInstances);
		        					userActionListType.numOfInstances = no;
		        				}
		        				var actionType :Object  = userActionList.actionType;
		        				if (actionType != null){

		        					termUseType = new TermUseType();
		        					var nameTypeObj:String = String(actionType.stringValue);
		        					if (nameTypeObj != null){

		        						nameType = new NameType();
		        						termUseType.nameArray = new Array();
										nameType.name = nameTypeObj;
										nameType.stringValue = nameTypeObj;
		        						termUseType.nameArray.push(nameType);
		        						userActionListType.actionType = termUseType;
		        					}
		        				}
		        				var userAction:Array = userActionList.userActionArray;
		        				if (userAction != null &&
		        					userAction.length > 0){

		        					userActionListType.userActionArray = new Array();
		        					for(var userActionArrayCount:int = 0; userActionArrayCount < userAction.length; userActionArrayCount ++){

		        						userActionType = new UserActionType();
		        						userActionObj = Object(userAction[userActionArrayCount]);
		        						actionTimeObj = userActionObj.actionTime;
		        						if (actionTimeObj != null){

		        							actionTime = new UserActionType_ActionTime();
		        							generalTimeObj  = actionTimeObj.generalTime;
		        							if (generalTimeObj != null){

		        								actionTime.generalTime = new TimeType();
		        								durationStr = String(generalTimeObj.duration);
		        								if (durationStr != null){
		        									actionTime.generalTime.duration = durationStr;
		        								}
		        								timePointStr = String(generalTimeObj.timePoint);
		        								if (timePointStr != null){
		        									actionTime.generalTime.timePoint = timePointStr;
		        								}
		        							}
		        							userActionType.actionTime = actionTime;
	        							}
		        						programIdentifier = userActionObj.programIdentifier;
		        						userActionType.timeBase = userActionObj.timeBase;
		        						if (programIdentifier != null){

		        							uniqueIdType = new UniqueIDType();
		        							uniqueIdType.organization = String(programIdentifier.organization);
		        							uniqueIdType.stringValue = String(programIdentifier.organization);
		        							uniqueIdType.programIdentifier = String(programIdentifier.organization);
		        							userActionType.programIdentifier = uniqueIdType;
		        						}
		        						userActionListType.userActionArray.push(userActionType);
		        					}
	        					}
	        					userActionHistoryType.userActionListArray.push(userActionListType);
        					}
        				}
	    				usageHistoryType.userActionHistoryArray.push(userActionHistoryType);
	    			}
	    		}
	    		if (userIdentifierObj != null){

	        		userIdentifier = new UserIdentifierType();
	        		if (userIdentifierObj.name != null) {
		        		
		        		var nameObj :String = String(userIdentifierObj.name.stringValue);
		        		if (nameObj != null){
	
		        			name  = new TextualType();
		        			name.name = nameObj;
		        			name.stringValue = nameObj;
		        			userIdentifier.name = name;
		        		}
		        		usageHistoryType.userIdentifier = userIdentifier;
		    		}
		    	}
	    	}
	  		return usageHistoryType;
		}
		
		/**
		 * Method to get the userInformationTable from the profile constructed
		 * 
		 */
		public static function processUserInformationTable(profileInfo:ProfileInfo):UserInformationTableType {

			var userInformationTableType:UserInformationTableType = new UserInformationTableType();
			var userInformationType:UserInformationType = new UserInformationType();
			var biographicInformationType:BiographicInformationType = new BiographicInformationType();
			biographicInformationType.age = Number(profileInfo.age);
			biographicInformationType.gender = String(profileInfo.gender);
			var personNameType:PersonNameType = new PersonNameType();
			var gN:NameComponentType = new NameComponentType;
			gN.givenName = profileInfo.firstName;
			gN.stringValue = profileInfo.firstName;
			personNameType.givenNameArray = new Array();
			personNameType.givenNameArray.push(gN);
			var lN:NameComponentType = new NameComponentType;
			lN.linkingName = profileInfo.password;
			lN.stringValue = profileInfo.password;
			personNameType.linkingNameArray = new Array();
			personNameType.linkingNameArray.push(lN);
			var fN:NameComponentType = new NameComponentType;
			fN.familyName = profileInfo.lastName;
			fN.stringValue = profileInfo.lastName;
			personNameType.familyNameArray = new Array();
			personNameType.familyNameArray.push(fN);
			biographicInformationType.nameArray = new Array();
			biographicInformationType.nameArray.push(personNameType);
			userInformationType.biographicInformationArray = new Array();
			userInformationType.userInformationId =  profileInfo.userId;
			userInformationType.biographicInformationArray.push(biographicInformationType);
			userInformationTableType.userInformationArray = new Array();
			userInformationTableType.userInformationArray.push(userInformationType);
			return userInformationTableType
		}
 	
 		public static function retrieveAssets(packageTable : Object) : Array{
			
			var assetsArray : Array = new Array();
			var assetItem : AssetItem = null;
			
			var packageArray : Array = packageTable.packageArray;
			if (packageArray == null) return assetsArray;
			for (var packCount : int  = 0; packCount < packageArray.length; packCount++){
				var descriptorArray : Array = packageArray[packCount].descriptorArray;
				if (descriptorArray == null) continue;
				for (var descCount : int = 0; descCount < descriptorArray.length; descCount++){
					var objDescriptorArray : Array = descriptorArray[descCount].objectDescriptionArray;
					if (objDescriptorArray == null) continue;
					for (var objDescCount : int  = 0; objDescCount < objDescriptorArray.length; objDescCount++){
						var objDescriptor : Object = objDescriptorArray[objDescCount];
						if (objDescriptor == null || objDescriptor.contentDescription == null || 
								objDescriptor.contentDescription.contentProperties == null)
								continue;
						var objContentDesc : Object =  objDescriptor.contentDescription;
						var objContentProperties : Object = objContentDesc.contentProperties;
						var objFileProperties : Object =  objContentProperties.fileProperties;
						var contentTypeArray : Array = objContentProperties.contentTypeArray;
						assetItem = new AssetItem();
						if (objFileProperties != null){
							assetItem.assetSize = MetasoftUtils.formatFileSize(objFileProperties.fileSize);
							var objFileFormat : Object = objFileProperties.fileFormat;
							if (objFileFormat != null)
							{
								var objFileFormatName : Object = objFileFormat.name;
								var objFileFormatDef : Object = objFileFormat.definition;
								if (objFileFormatName != null)
									assetItem.assetType = objFileFormatName.stringValue;
//								if (objFileFormatDef != null)
//									assetItem.assetType = objFileFormatDef.stringValue;
							}
						}
						for (var contentTypeCount : int  = 0; contentTypeCount < contentTypeArray.length; contentTypeCount++){
							var objContentType : Object = contentTypeArray[contentTypeCount];
							if (objContentType != null)
							{
								var objContentTypeName : Object = objContentType.name;
								if (objContentTypeName != null){
									assetItem.assetName = objContentTypeName.stringValue;
									if (assetItem.assetName != null && assetItem.assetName.indexOf(".")  != -1)
									{
										assetItem.assetExtn = assetItem.assetName.substr(assetItem.assetName.lastIndexOf(".") + 1);
									}
								}
							}
						}
						if (assetItem != null) 
						{
							assetsArray.push(assetItem);
						}
					}
				}
			}
			return assetsArray;
		}
		
		/**
		 * Method to set the file information to the server
		 * */
    	public static function retrieveDescriptors(packageCRID : String, assetObj : Object, descriptors : Array) : Array
		{ 
 				var descriptorType:DescriptorType  =  new DescriptorType();
		 		descriptorType.objectDescriptionArray = new Array();	
		 		descriptorType.descriptorId = packageCRID + ":" + assetObj.name;
 				var objectDescriptor:ObjectDescriptionType = new ObjectDescriptionType();
			    var contentDescription: ExtendedContentDescriptionType = new  ExtendedContentDescriptionType();
 			    var contentProperties: ContentPropertiesType = new  ContentPropertiesType();
 		     	contentProperties.contentTypeArray = new Array();
 		     	var contentType:ControlledTermType = new ControlledTermType();
 			    contentType.name = new TermNameType();
			    contentType.name.stringValue = assetObj.name;
			    contentType.definition = new TextualType();
			    contentType.definition.stringValue = assetObj.name;
			    contentProperties.contentTypeArray.push(contentType);
 			    contentProperties.fileProperties = new FilePropertiesType();
  			  	contentProperties.fileProperties.fileFormat = new ControlledTermType();
			 	contentProperties.fileProperties.fileFormat.href = "";
  			 	contentProperties.fileProperties.fileFormat.name = new TermNameType();
  			 	var type : String = assetObj.type;
				if (type == null){
			
					if (assetObj.name != null && assetObj.name.length > 0){
				
						var strObj : String = String (assetObj.name);
						var assetExtn : String = strObj.substr(strObj.indexOf("."));
						type = MetasoftUtils.getFileType(assetExtn);
					}
				}
  			 	contentProperties.fileProperties.fileFormat.name.stringValue = type;
			 	contentProperties.fileProperties.fileFormat.definition = new TextualType();
	 		 	contentProperties.fileProperties.fileFormat.definition.stringValue =  MetasoftUtils.getFileType(assetObj.file.type);
			 	contentProperties.fileProperties.fileSize = MetasoftUtils.unFormatFileSize(assetObj.size);
			    contentDescription.contentProperties = contentProperties;
			    objectDescriptor.contentDescription = contentDescription;
			    descriptorType.objectDescriptionArray.push(objectDescriptor);
				descriptors.push(descriptorType);
				return descriptors;
		}
		
		
		public static  function retrievePackage(descriptors : Array, cridID : String):TVAMainDocument
		{
			var tvaMainDoc: TVAMainDocument = new TVAMainDocument();
		   	var tvaMain : ExtendedTVAMainType = new ExtendedTVAMainType();
			var packageTable:PackageTableType = new PackageTableType();
			packageTable.packageArray = new Array();
			var packageType:PackageType = new PackageType();
			packageType.crid = cridID;
		 	packageType.descriptorArray = descriptors;
		    packageTable.packageArray.push(packageType);
		    tvaMain.packageTable = packageTable;
		    tvaMainDoc.TVAMain = tvaMain;
		    return tvaMainDoc;
		}
		
		public static function retrievedeletDataDoc(crid : String, targetTable : String, removedFileNames : String) : DeleteDataDocument
		{
			var deleteDataDoc : DeleteDataDocument  = new DeleteDataDocument();
			var deleteDataType : DeleteDataType  = new DeleteDataType();
			var removedFilesArray : Array = removedFileNames.split(",");
			deleteDataType.CRIDArray = new Array();
				
			for (var i : int = 0; i < removedFilesArray.length ; i ++)
			{
				if (removedFilesArray[i] == "") continue;
				var descCrid : TVAIDType  = new TVAIDType();
				descCrid.stringValue = crid + ":" + removedFilesArray[i];
				deleteDataType.CRIDArray.push(descCrid);
			}
			
			var deleteTableType_Enum : DeleteTableType_Enum = new DeleteTableType_Enum();
			deleteTableType_Enum.stringValue = targetTable;
			deleteDataType.targetTableArray = new Array();
			deleteDataType.targetTableArray.push(deleteTableType_Enum);
			deleteDataDoc.deleteData = deleteDataType;
			return deleteDataDoc;
		}
		
		public static function getDataQuery(fieldID:String, fieldValue:String, tableName:String, test:String):GetDataDocument {

 			var getDataDocument:GetDataDocument = new GetDataDocument;
	        var getDataType:GetDataType = new GetDataType;
	        var queryConstraints:QueryConstraintsInfo  = new QueryConstraintsInfo;
	        var predicateBagType:PredicateBagType  = new PredicateBagType;
	        var binaryPredicateType:BinaryPredicateType = new BinaryPredicateType;
	        binaryPredicateType.fieldID = fieldID;
	        binaryPredicateType.fieldValue = fieldValue;
	        
	        binaryPredicateType.test = test;
	        var binaryPredicateTypes:Array = new Array;
	        binaryPredicateTypes[0] = binaryPredicateType;
	        predicateBagType.binaryPredicateArray = binaryPredicateTypes;
	        queryConstraints.predicateBag =predicateBagType;
	        getDataType.queryConstraints=queryConstraints;
	        var reqTables:RequestedTablesType = new RequestedTablesType;
	        var tableType:TableType = new TableType;
	        tableType.type=tableName;
	        var tables:Array = new Array;
	        var tab:TableType = new TableType;
	        tables[0] = tableType;
	        reqTables.tableArray = tables;
	        getDataType.requestedTables = reqTables;
	        getDataDocument.getData = getDataType;
	        return getDataDocument;
		}
		
		public static function getDefaultPIQuery():GetDataDocument {

 			var getDataDocument:GetDataDocument = new GetDataDocument;
	        var getDataType:GetDataType = new GetDataType;
	        var queryConstraints:QueryConstraintsInfo  = new QueryConstraintsInfo;
	        var predicateBagType:PredicateBagType  = new PredicateBagType;
	        var binaryPredicateTypes:Array = getBinaryPredicateArray();

	        predicateBagType.binaryPredicateArray = binaryPredicateTypes;
	        queryConstraints.predicateBag =predicateBagType;
	        getDataType.queryConstraints=queryConstraints;
	        var reqTables:RequestedTablesType = new RequestedTablesType;
	        var tableType:TableType = new TableType;
	        tableType.type= MetasoftULC.Req_Table_ProgramInformationTable;
	        var tables:Array = new Array;
	        var tab:TableType = new TableType;
	        tables[0] = tableType;
	        reqTables.tableArray = tables;
	        getDataType.requestedTables = reqTables;
	        getDataDocument.getData = getDataType;
	        return getDataDocument;
		}
		
		private static function getBinaryPredicateArray():Array {
			
			var binaryPredicateTypes:Array = new Array;
			var defaultGroupId:String = getGroupID();
			
			if(defaultGroupId !=null) {
				
				var binaryPredicateType:BinaryPredicateType = new BinaryPredicateType;
				binaryPredicateType.fieldID = MetasoftULC.MemberOf;
				binaryPredicateType.fieldValue = defaultGroupId;
				binaryPredicateType.test = MetasoftULC.Equals;
				binaryPredicateTypes.push(binaryPredicateType);
			}

			return binaryPredicateTypes;
		}
		
		/**
	 	 * Constructing GroupId.
	 	 */
		public static function getGroupID():String {
			
			var groupId:String = new String;
			var so:SharedObject = SharedObject.getLocal(MetasoftULC.LoggedInUser);
			var serviceOwner:String = so.data.userId;
		
			if(serviceOwner!=null)
				groupId = MetasoftULC.CRID_NAME + serviceOwner ;
			
			return groupId;
		}
		
		/**
	 	 * Constructing and Calling MetasoftFlexAdmin's updateGroupInformation Service 
	 	 */
		public static function updateGroupInformation(groupId:String, existPIList:Array, currentPIList:ArrayCollection, callBack:Function):void {

			var progList:Array = constructPIGroup(groupId, currentPIList);
			var metasoftService:MetasoftService = new MetasoftService;
			var remoteObj:mx.rpc.remoting.mxml.RemoteObject = metasoftService.getRemoteUtilObject();
			remoteObj.updateGroupInformation.addEventListener(ResultEvent.RESULT, callBack);
			remoteObj.updateGroupInformation(groupId, getPIList(existPIList), progList);
		}
		
			
		/**
	 	 * Getting ProgramInfo List 
	 	 */
		private static function getPIList(existPIList:Array):Array {
			
			var piList:Array = new Array;
			if(existPIList !=null && existPIList.length !=0) {
				
				var pi:Object = new Object();
				for each(pi in existPIList) {
					
					if (pi.id != null) {
						
					 	piList.push(pi.id);
					 }
				}
			}
			
			return piList;
		}
		
		/**
	 	 * constructing ProgramInfo Group. 
	 	 */
		private static function constructPIGroup(groupId:String, piList:ArrayCollection):Array {
			
			var memberOfArray:Array = new Array;
			if(piList!=null && piList.length !=0) {
				
				var piObject:Object = new Object();
				var count:Number = 1;
				for each(piObject in piList) {
					
					if(piObject !=null) {

						var memberOf:BaseMemberOfType = new BaseMemberOfType;
						if(piObject.id !=null) {
							memberOf.crid = piObject.id;
						}
						memberOf.index = count;
						memberOfArray.push(memberOf);
						count = count + 1;
					}
				}
			}
			return memberOfArray;
		}
		
		/**
	 	 * constructing TVAMainDocument for limited elements. 
	 	 */
		public static function constructPISubmitData(title:String, keyword:String, synopsis:String,
						genreName:String, genreHref:String, groupId:String, location:String, 
						thumbnail:String, duration:String):TVAMainDocument {
			
				var tvaMainDoc:TVAMainDocument = new TVAMainDocument;
				var tvaMain:ExtendedTVAMainType = getExtendedTVAMain(null, title, keyword, synopsis,
						genreName, genreHref, groupId, location, thumbnail, duration);
						
				tvaMainDoc.TVAMain = tvaMain;
				
				return tvaMainDoc;
		}
		
		/**
	 	 * constructing TVAMainDocument Object 
	 	 */
		public static function getTVADocument(product:Product, programId:String, groupId:String, segmentFlag:Boolean):TVAMainDocument {
			
			var tvaMainDoc:TVAMainDocument = new TVAMainDocument;
			var tvaMain:ExtendedTVAMainType = getExtendedTVADocument(product, programId, groupId, segmentFlag);

			tvaMainDoc.TVAMain = tvaMain;
			
			return tvaMainDoc;
		}
		
		/**
	 	 * constructing ExtendedTVAMainDocment Object 
	 	 */
		private static function getExtendedTVAMain(programId:String, title:String, keyword:String, synopsis:String,
						genreName:String, genreHref:String, groupId:String, location:String, 
						thumbnail:String, duration:String):ExtendedTVAMainType {
			
				var tvaMain:ExtendedTVAMainType = new ExtendedTVAMainType;
				var programDesc:ProgramDescriptionType = new ProgramDescriptionType;
				var programInfoTable:ProgramInformationTableType = new ProgramInformationTableType;
				var programInfoArray:Array = new Array;
				var programInfo:ProgramInformationType = new ProgramInformationType;
				var basicContent:BasicContentDescriptionType = new BasicContentDescriptionType;
				
				var titleArray:Array = new Array;
				var synopsisArray:Array = new Array;
				var keywordArray:Array = new Array;
				var genreTypeArray:Array = new Array;
				
				var titleType:TitleType = new TitleType;
				var synopsisType:SynopsisType = new SynopsisType;
				var keywordType:KeywordType = new KeywordType;
				var genreType:GenreType = new GenreType;
				
				var synopsisLength:SynopsisLengthType = new SynopsisLengthType;
				
				if(title !=null) {
					
					titleType.lang = title;
					titleType.stringValue = title;
					titleArray.push(titleType);
					basicContent.titleArray = titleArray;
				}
				
				if(keyword !=null) {
					
					keywordType.lang = keyword;
					keywordType.stringValue = keyword;
					keywordArray.push(keywordType);
					basicContent.keywordArray = keywordArray;
				}
				
				if(synopsis !=null) {
				
					synopsisType.stringValue = synopsis;
					synopsisLength.length = "short";
					synopsisType.length = synopsisLength
					synopsisArray.push(synopsisType);
					basicContent.synopsisArray = synopsisArray;
				}
				
				if(genreName != null && genreHref !=null) {
	
					var tName:TermNameType = new TermNameType;
					genreType.href = genreHref;
					tName.stringValue = genreName;
					tName.lang = genreName;
					genreType.name = tName;
					genreTypeArray.push(genreType);
					basicContent.genreArray = genreTypeArray;
				}
				
				if(location !=null) {
					
					var relatedMaterialArray:Array = new Array;
					var relatedMaterial:RelatedMaterialType = new RelatedMaterialType;
					var mediaLocator:MediaLocatorType = new MediaLocatorType;
					mediaLocator.mediaUri = location;
					relatedMaterial.mediaLocator = mediaLocator;
					relatedMaterialArray.push(relatedMaterial);
					basicContent.relatedMaterialArray = relatedMaterialArray;
				}
				
				if(thumbnail !=null) {
					
					var thumbnailType:ThumbnailType = new ThumbnailType;
					thumbnailType.lang = thumbnail;
					thumbnailType.stringValue = thumbnail;
				}
				if(duration !=null) {
					
					basicContent.duration = duration;
				}
				
				if(groupId !=null) {
						
					var memberOfArray:Array = new Array;
					var memberOf:BaseMemberOfType = new BaseMemberOfType();
					
					memberOf.crid = groupId;
					memberOf.index =1;
					memberOfArray.push(memberOf);
					
					programInfo.memberOfArray = memberOfArray;
				}
				
				if(programId !=null && programId.length !=0)
					programInfo.programId = programId;
				
				programInfo.basicDescription = basicContent;
				programInfoArray.push(programInfo);
				
				programInfoTable.programInformationArray = programInfoArray;
				programDesc.programInformationTable = programInfoTable;
				tvaMain.programDescription = programDesc;
				tvaMain.publicationTime = "2006-09-15T00:00:00Z";
				
				return tvaMain;
		}
		
/*		public static function modifyPISubmitData(programId:String, title:String, keyword:String, synopsis:String,
						genreName:String, genreHref:String, groupId:String, location:String, 
						thumbnail:String, duration:String):ModifyDocument {
*/
		/**
	 	 * constructing Modifiy PI Submit Data
	 	 */
		public static function modifyPISubmitData(product:Product, programId:String, groupId:String):ModifyDocument {

				var modify:ModifyType 				= new ModifyType();
				
				//Modification for ProgramInfo 
				var modification:Modification	 	= new Modification();
				var selectType:SelectType 			= new SelectType();

				selectType.type 	= "abbreviated";
				selectType.select 	= MetasoftULC.Req_Table_ProgramInformationTable;
				selectType.stringValue 	= MetasoftULC.Req_Table_ProgramInformationTable;

				modification.select = selectType;
				modification.itemID = MetasoftULC.Req_Table_ProgramInformationTable;
				
				var newData:NewData  			=  new NewData();
				var tvaMain:ExtendedTVAMainType = new ExtendedTVAMainType();
		
				//tvaMain = getExtendedTVAMain(programId, title, keyword, synopsis, genreName, genreHref, groupId, location, thumbnail, duration);
						
				tvaMain = getExtendedTVADocument(product, programId, groupId, false);

				newData.TVAMain 			= tvaMain;
				modification.newData		= newData;
				
				//Modification for Segmentation
				var modificationSI:Modification	 	= new Modification();
				var selectTypeSI:SelectType 			= new SelectType();

				selectTypeSI.type 	= "abbreviated";
				selectTypeSI.select 	= MetasoftULC.Req_Table_SegmentInformationTable
				selectTypeSI.stringValue 	= MetasoftULC.Req_Table_SegmentInformationTable;

				modificationSI.select = selectTypeSI;
				modificationSI.itemID = MetasoftULC.Req_Table_SegmentInformationTable;
				
				var newDataSI:NewData  			=  new NewData();
				var tvaMainSI:ExtendedTVAMainType = new ExtendedTVAMainType();
				var programDesc:ProgramDescriptionType = new ProgramDescriptionType;
		
				tvaMainSI = getExtendedTVADocument(product, programId, groupId, false);
				//Segmentation Info Details
				var segmentInfoTable:SegmentInformationTableType = constructSegmentInfo(programId, product);
				if(segmentInfoTable !=null)
					programDesc.segmentInformationTable = segmentInfoTable;

				tvaMainSI.programDescription = programDesc;
				
				newDataSI.TVAMain 			= tvaMainSI;
				modificationSI.newData		= newDataSI;
				
				modify.modificationArray 	= new Array();
				modify.modificationArray.push(modification);
				modify.modificationArray.push(modificationSI);
				
				var modifyDoc:ModifyDocument = new ModifyDocument();
				modifyDoc.modify = modify;
				return modifyDoc;
		}
		
		/**
	 	 * constructing delete Query
	 	 */
		public static function getDeleteQuery(cridArr:Array, targetTable:String):DeleteDataDocument 
		{
			if (cridArr == null || cridArr.length == 0 || targetTable == null || targetTable.length == 0){
				return null;
			}
			var deleteQuery:DeleteDataDocument = new DeleteDataDocument();
			var deleteDataType : DeleteDataType  = new DeleteDataType();
			var deleteTableType_Enum : DeleteTableType_Enum = new DeleteTableType_Enum();
		    deleteTableType_Enum.stringValue = targetTable;
		    deleteDataType.targetTableArray = new Array();
		    deleteDataType.targetTableArray.push(deleteTableType_Enum);
			for (var cridCount : int = 0; cridCount < cridArr.length; cridCount++) 
			{
				var crid:String = cridArr[cridCount] as String;
				if(crid !=null) 
				{
					var descCrid : TVAIDType  = new TVAIDType();
					descCrid.stringValue = crid;
					deleteDataType.CRIDArray = new Array;
					deleteDataType.CRIDArray.push(descCrid);
				}
		   }
		   deleteQuery.deleteData = deleteDataType;
		   return deleteQuery;
		}
		
		/**
	 	 * loading groupInformationArray
	 	 */
   		public static function loadGroupInfoDTos(groupInformationArray:Array):void {
			
			var groupInfoArray:Array = new Array;
			if (groupInformationArray != null && groupInformationArray.length > 0) {

				var groupInfo:Object = new Object();
				for each(groupInfo in groupInformationArray) {
					
					if(groupInfo.groupId == MetasoftHelper.getGroupID()) 
						continue;
						
					var groupDTO:GroupInfoDTO = new GroupInfoDTO;
					groupDTO.groupID = groupInfo.groupId;
					var basicDescription:Object = groupInfo.basicDescription as Object;
					if (basicDescription != null) {
						
						if (basicDescription.titleArray[0] != null) {
							
							if(basicDescription.titleArray[0].lang !=null)
								groupDTO.groupName = basicDescription.titleArray[0].lang;
							else
								groupDTO.groupName = basicDescription.titleArray[0].stringValue;
						}
						
						if (basicDescription.synopsisArray[0] != null) {
							
							if(basicDescription.synopsisArray[0].stringValue !=null)
								groupDTO.synopsis = basicDescription.synopsisArray[0].stringValue;
							else
								groupDTO.synopsis = basicDescription.titleArray[0].lang;
						}
						
						if (basicDescription.keywordArray[0] != null) {
							
							if(basicDescription.keywordArray[0].lang !=null)
								groupDTO.keyword = basicDescription.keywordArray[0].lang;
							else
								groupDTO.keyword = basicDescription.keywordArray[0].stringValue;
						}
						
						if (basicDescription.thumbnail != null) {
							groupDTO.thumbnail = basicDescription.thumbnail.stringValue;
						}
						
						if (basicDescription.author != null) {
							groupDTO.author = basicDescription.author.stringValue;
						}
						
						if(basicDescription.genreArray !=null && basicDescription.genreArray.length !=0) {
							
							var genreArray:Array = basicDescription.genreArray;
							var genre:Object = new Object;
							for each(genre in genreArray) {

								if (genre == null) { 
									continue;
								}
								var href:String  = genre.href;
								if (href != null) {
									groupDTO.genreHref = href;
									if (genre.name != null){
										groupDTO.genreName = genre.name.stringValue;
									}
								}
							}

						}
					}
					groupInfoArray.push(groupDTO);
				}
				if(groupInfoArray !=null && groupInfoArray.length !=0)
					loadGroupInfo(groupInfoArray);
			}
		}
		
		/**
	 	 * loading serviceInformationArray
	 	 */
   		public static function loadServiceInfoDTOs(serviceInformationArray:Array):void {
			
			var serviceInfoArray:Array = new Array;
			if (serviceInformationArray != null && serviceInformationArray.length > 0) {

				var serviceInfo:Object = new Object();
				for each(serviceInfo in serviceInformationArray) {
					
					var serviceInfoDTO:ServiceInfoDTO = new ServiceInfoDTO;
					serviceInfoDTO.owner = serviceInfo.owner;
					serviceInfoDTO.serviceURL = serviceInfo.serviceURL;
					serviceInfoDTO.serviceId = serviceInfo.serviceId;
					
					var nameArray:Array = serviceInfo.nameArray;
					if (nameArray != null && nameArray.length >0) {
						
						if (nameArray[0] != null) {
							
							if(nameArray[0].lang !=null)
								serviceInfoDTO.serviceName = nameArray[0].lang;
							else
								serviceInfoDTO.serviceName = nameArray[0].stringValue;
						}
					}
					serviceInfoArray.push(serviceInfoDTO);
				}
				if(serviceInfoArray !=null && serviceInfoArray.length !=0)
					loadServiceInfo(serviceInfoArray);
			}
		}		
		
		/**
	 	 * loading groupDTOArray for global access
	 	 */
		public static function loadGroupInfo(groupDTOArray:Array):void {

        	var so:SharedObject = SharedObject.getLocal(MetasoftULC.LoggedInUser);
	        so.data.groupArray = groupDTOArray;
		}
		
		/**
	 	 * loading serviceDTOsArray for global access
	 	 */
		public static function loadServiceInfo(serviceDTOsArray:Array):void {

        	var so:SharedObject = SharedObject.getLocal(MetasoftULC.LoggedInUser);
	        so.data.serviceInfoArray = serviceDTOsArray;
		}
		
		/**
	 	 * getting Shared GroupInfo Object
	 	 */
		public static function getGroupInfoDetails():Array {
			
			var groupInfoArray:Array = new Array; 
        	var so:SharedObject = SharedObject.getLocal(MetasoftULC.LoggedInUser);
	        groupInfoArray = so.data.groupArray;
			
			return groupInfoArray;
		}
		
		/**
	 	 * Clearing selected Shared GroupInfo Object
	 	 */
		public static function clearSelectedGroup() :void {
				
				var so:SharedObject = SharedObject.getLocal(MetasoftULC.LoggedInUser);
				so.data.seletedGroup=null; 
		}
		
		/**
	 	 * Clearing selected Shared PI Object
	 	 */
		public static function clearSelectedProgramInfo() :void {
				
			var so:SharedObject = SharedObject.getLocal(MetasoftULC.LoggedInUser);
			so.data.seletedProgramInfo=null; 
		}
		
	    /**
	 	 * Loads the groupInformation information of the logged in user
	 	 */
	 	public static function loadGroupInfoTable(groupInfoTable:Object):void {
	 		
	 		var groupInformationArray:Array = new Array;
			if(groupInfoTable !=null) {

				groupInformationArray = groupInfoTable.groupInformationArray;
				if(groupInformationArray !=null && groupInformationArray.length !=0) {

					loadGroupInfoDTos(groupInformationArray);
				}
			}
	   	}
	   
	    /**
	 	 * Loads the serviceInformation information of the logged in user
	 	 */
	 	public static function loadServiceInfoTable(serviceInfoTable:Object):void {
	 		
	 		var serviceInformationArray:Array = new Array;
			if(serviceInfoTable !=null) {

				serviceInformationArray = serviceInfoTable.serviceInformationArray;
				if(serviceInformationArray !=null && serviceInformationArray.length !=0) {

					loadServiceInfoDTOs(serviceInformationArray);
				}
			}
	   }
	   
	   /**
	   * contructing Genre Object.
	   * @param genreName - Genre Name of particular Classification Schema.
	   * @param genreHref - Genre Href of particular Classification Schema.
	   */
	   public static function constructGenre(genreName:String, genreHref:String):Object {
			
			var genreType:GenreType = new GenreType;
			var tName:TermNameType = new TermNameType;
			
			genreType.href = genreHref;
			tName.stringValue = genreName;
			tName.lang = genreName;
			genreType.name = tName;
			
			return genreType;
		}
	    
	   /**
	   * contructing Parental Guidance Object.
	   * @param guidanceName - Name of particular Parental Guidance Schema.
	   * @param guidanceHref - Href of particular Parental Guidance Schema.
	   */
	   public static function constructParentalGuidance(guidanceName:String, guidanceHref:String):ParentalGuidanceType {
			
			var parentalGuidance:ParentalGuidanceType = new ParentalGuidanceType;
			var parentRating:ControlledTermUseType = new ControlledTermUseType;
			parentRating.href = guidanceHref;
			parentalGuidance.parentalRating = parentRating;
			
			return parentalGuidance;
		}

	   /**
	   * contructing TVAMainDocument based on Product Object.
	   * @param product - ProgramInformation Object.
	   * @param programId - PI's programId which is used for updating existing PI. 
	   * @param groupId - PI's groupId is used for grouping this Program Information. 
	   */
		public static function getExtendedTVADocument(product:Product, programId:String, groupId:String, segmentFlag:Boolean):ExtendedTVAMainType {
			
				//var tvaMainDoc:TVAMainDocument = new TVAMainDocument;
				var tvaMain:ExtendedTVAMainType = new ExtendedTVAMainType;
				var programDesc:ProgramDescriptionType = new ProgramDescriptionType;
				var programInfoTable:ProgramInformationTableType = new ProgramInformationTableType;
				var programInfoArray:Array = new Array;
				var programInfo:ProgramInformationType = new ProgramInformationType;
				var basicContent:BasicContentDescriptionType = new BasicContentDescriptionType;
				
				var titleArray:Array = new Array;
				var synopsisArray:Array = new Array;
				var keywordArray:Array = new Array;
				var genreTypeArray:Array = new Array;
				var languageArray:Array = new Array;

    			var titleType:TitleType = new TitleType;
				var synopsisType:SynopsisType = new SynopsisType;
				var keywordType:KeywordType = new KeywordType;
				var genreType:GenreType = new GenreType;
				var synopsisLength:SynopsisLengthType = new SynopsisLengthType;
				
				//Title
				var title:String = product.title;
				if(title !=null && title.length !=0) {
					
					titleType.lang = title;
					titleType.stringValue = title;
					titleArray.push(titleType);
					basicContent.titleArray = titleArray;
				}
				
				//Keyword
				var keyword:String = product.keyword;
				if(keyword !=null && keyword.length !=0) {
					
					keywordType.lang = keyword;
					keywordType.stringValue = keyword;
					keywordArray.push(keywordType);
					basicContent.keywordArray = keywordArray;
				}
				
				//Synopsis
				var synopsis:String = product.synopsis;			
				if(synopsis !=null && synopsis.length !=0) {
				
					synopsisType.stringValue = synopsis;
					synopsisLength.length = "short";
					synopsisType.length = synopsisLength
					synopsisArray.push(synopsisType);
					basicContent.synopsisArray = synopsisArray;
				}
				
				//Genre
				var genreArray:Array = product.genreArray;
				if(genreArray != null && genreArray.length !=0) {
	
					basicContent.genreArray = genreArray;
				}
				
				//Related Material Location
				var location:String = product.officialURI;
				var promo:String = product.promoInfo;
				if(location !=null || promo !=null) {
					
					var relatedMaterialArray:Array = new Array;
					var promoArray:Array = new Array;
					var relatedMaterial:RelatedMaterialType = new RelatedMaterialType;
					
					//MediaURL
					if(location !=null && location.length !=0) {
						
						var mediaLocator:MediaLocatorType = new MediaLocatorType;
						mediaLocator.mediaUri = location;
						relatedMaterial.mediaLocator = mediaLocator;
					}
					
					//Promotional Info
					if(promo !=null && promo.length !=0) {
						
						var promoText:TextualType = new TextualType;
						promoText.stringValue = promo;
						promoText.stringValue = promo;
						promoArray.push(promoText);
						relatedMaterial.promotionalTextArray = promoArray;
					}
					
					relatedMaterialArray.push(relatedMaterial);
					basicContent.relatedMaterialArray = relatedMaterialArray;
				}
				
				//Thumbnail
				var thumbnail:String = product.thumbnail;
				if(thumbnail !=null && thumbnail.length !=0) {
					
					var thumbnailType:ThumbnailType = new ThumbnailType;
					//thumbnailType.lang = thumbnail;
					thumbnailType.stringValue = thumbnail;
					basicContent.thumbnail = thumbnailType;
				}
				
				//Preview
				var preview:String = product.preview;
				if(preview !=null && preview.length !=0) {
					
					var previewType:PreviewType = new PreviewType;
					//previewType.lang = preview;
					previewType.stringValue = preview;
					basicContent.preview = previewType;
				}
				
				//Duration
				var duration:String = product.duration;
				if(duration !=null && duration.length !=0) {
					
					basicContent.duration = duration;
				}
				
				//Cost
				var cost:String = product.price;
				if(cost !=null && cost.length !=0) {
					
					var costType:CostType = new CostType;
					costType.stringValue = cost;

					basicContent.cost = costType;
				}
				
				//Author
				var author:String = product.author;
				if(author !=null && author.length !=0) {
					
					var authorType:AuthorType = new AuthorType;
					//authorType.lang = author;
					authorType.stringValue = author;

					basicContent.author = authorType;
				}
				
				//Language
				/*var language:String = product.language;
				if(language !=null && language.length !=0) {
					
					var languageArray:Array = new Array;
					var languageType:ExtendedLanguageType = new ExtendedLanguageType;
					languageType.type = language;
					languageArray.push(languageType);
					
					//basicContent.languageArray = languageArray;
				}*/
				
				//CopyRight
				var copyRight:String = product.copyRight;
				if(copyRight !=null && copyRight.length !=0) {
					
					var copyRightType:CopyrightType = new CopyrightType;
					copyRightType.stringValue = copyRight;
					
					basicContent.copyright = copyRightType;
				}
				
				//ParentalGuidance
				var parentalGuidanceArray:Array = product.parentalGuidanceArray;
				if(parentalGuidanceArray !=null && parentalGuidanceArray.length !=0)
					basicContent.parentalGuidanceArray = parentalGuidanceArray;
					
				//CreditItemList
				var creditorArray:ArrayCollection = product.creditorArray;
				if(creditorArray !=null && creditorArray.length !=0) {
					
					var creditsList:CreditsListType = constructCreditItemList(product);
					if(creditsList !=null)
						basicContent.creditsList = creditsList;
				}
					
				//AwardList
				var awardListArray:ArrayCollection = product.awardListArray;
				if(awardListArray !=null && awardListArray.length !=0) {
					
					var awardsList:AwardsListType = constructAwardList(product);
					if(awardsList !=null)
						basicContent.awardsList = awardsList;
				}
				
				//MemberOf
				if(groupId !=null && groupId.length !=0) {

					var memberOfArray:Array = new Array;
					var memberOf:BaseMemberOfType = new BaseMemberOfType();
					
					memberOf.crid = groupId;
					memberOf.index =1;
					memberOfArray.push(memberOf);
					
					programInfo.memberOfArray = memberOfArray;
				}
				
				var crid:String = "";
				if(programId !=null && programId.length !=0) {
					crid = programId;
				} else {
					
					if(title !=null && title.length !=0) {
						crid = constructProgramId(replaceEmptyString(title));
					}
				}
				
				programInfo.programId = crid;
				
				programInfo.basicDescription = basicContent;
				programInfoArray.push(programInfo);
				
				programInfoTable.programInformationArray = programInfoArray;
				programDesc.programInformationTable = programInfoTable;
				
				if(segmentFlag) {

					//Segmentation Info Details
					var segmentInfoTable:SegmentInformationTableType = constructSegmentInfo(crid, product);
					if(segmentInfoTable !=null)
						programDesc.segmentInformationTable = segmentInfoTable;
				}
					
				tvaMain.programDescription = programDesc;
				tvaMain.publicationTime = "2008-01-1T00:00:00Z";
				
				//tvaMainDoc.TVAMain = tvaMain;
				return tvaMain;
		}
		
	   /**
	   * contructing TVAMainDocument based on Product Object.
	   * @param product - ProgramInformation Object.
	   * @param programId - PI's programId which is used for updating existing PI. 
	   * @param groupId - PI's groupId is used for grouping this Program Information. 
	   */
		public static function getTestTVADocument():TVAMainDocument {
			
				var tvaMainDoc:TVAMainDocument = new TVAMainDocument;
				var tvaMain:ExtendedTVAMainType = new ExtendedTVAMainType;
				var programDesc:ProgramDescriptionType = new ProgramDescriptionType;
				var programInfoTable:ProgramInformationTableType = new ProgramInformationTableType;
				var programInfoArray:Array = new Array;
				var programInfo:ProgramInformationType = new ProgramInformationType;
				var basicContent:BasicContentDescriptionType = new BasicContentDescriptionType;
				
				var titleArray:Array = new Array;
				var synopsisArray:Array = new Array;
				var keywordArray:Array = new Array;
				var genreTypeArray:Array = new Array;
				var parentalGuidanceArray:Array = new Array;
				var languageArray:Array = new Array;

    			var titleType:TitleType = new TitleType;
				var synopsisType:SynopsisType = new SynopsisType;
				var keywordType:KeywordType = new KeywordType;
				var genreType:GenreType = new GenreType;
				var synopsisLength:SynopsisLengthType = new SynopsisLengthType;
				
				//Title
				var title:String = "Credit Title ";
				if(title !=null && title.length !=0) {
					
					titleType.lang = title;
					titleType.stringValue = title;
					titleArray.push(titleType);
					basicContent.titleArray = titleArray;
				}
				
				//Related Material Location
				
				var promo:String = "This is from Sample Promo";
				var location:String = "http://www.google.com";
				if(location !=null || promo !=null) {
					
					var relatedMaterialArray:Array = new Array;
					var promoArray:Array = new Array;
					var relatedMaterial:RelatedMaterialType = new RelatedMaterialType;
					
					//MediaURL
					if(location !=null && location.length !=0) {
						
						var mediaLocator:MediaLocatorType = new MediaLocatorType;
						mediaLocator.mediaUri = location;
						relatedMaterial.mediaLocator = mediaLocator;
						//relatedMaterialArray.push(relatedMaterial);
					}
					
					//Promotional Info
					if(promo !=null && promo.length !=0) {
						
						var promoText:TextualType = new TextualType;
						promoText.stringValue = promo;
						promoArray.push(promoText);
						relatedMaterial.promotionalTextArray = promoArray;
					}
					
					relatedMaterialArray.push(relatedMaterial);
					basicContent.relatedMaterialArray = relatedMaterialArray;
				}
				
				//Duration
				var duration:String = "PT45M";
				if(duration !=null && duration.length !=0) {
					
					basicContent.duration = duration;
				}

				//CopyRight
				var copyRight:String = "ALl Rights Reserved";
				if(copyRight !=null && copyRight.length !=0) {
					
					var copyRightType:CopyrightType = new CopyrightType;
					copyRightType.stringValue = copyRight;
					
					basicContent.copyright = copyRightType;
				}
				//Genre
				
				var genreArray = new Array;
				
				var categoryGenre:Object = MetasoftHelper.constructGenre("Non-Fiction/Infromation", "urn:tva:metadata:cs:ContentCS:2005:3.1");
				genreArray.push(categoryGenre);
				basicContent.genreArray = genreArray;
				//Language
				/*var language:String = "Tamil";
				if(language !=null && language.length !=0) {
					
					var languageArray:Array = new Array;
					var languageType:ExtendedLanguageType = new ExtendedLanguageType;
					//var type:Type = new Type;
					//type.type = language;
					languageType.type = language;
					languageArray.push(languageType);
					
					basicContent.languageArray = languageArray;
				}*/
				
				//CreditList
				var creditList:CreditsListType = new CreditsListType;
				var creditsItemArray:Array = new Array;
				
				var creditItem:CreditsItemType = new CreditsItemType;
				creditItem.role = MetasoftULC.RoleCS + "DIRECTOR";
				
				var personNameArray:Array = new Array;
				var personName:PersonNameType = new PersonNameType;
				var givenNameArray:Array = new Array;
				
				var nameComp:NameComponentType = new NameComponentType;
				nameComp.stringValue = "Ramesh Kumar";
				givenNameArray.push(nameComp);
				
				personName.givenNameArray = givenNameArray;
				personNameArray.push(personName);
				creditItem.personNameArray = personNameArray;
				
				creditsItemArray.push(creditItem);
				creditList.creditsItemArray = creditsItemArray;
				basicContent.creditsList = creditList;
				
				//AwardList
				var awardsList:AwardsListType = new AwardsListType;
				var awardListItemArray:Array = new Array;
				
				var awardListItem:AwardsListItemType = new AwardsListItemType;
				
				var awardArray:Array = new Array;
				var awardType:TextualType = new TextualType;
				awardType.stringValue = "Oscar Award";
				
				awardListItem.title = awardType;
				var award:AwardType = new AwardType;
				var recipient:CreditsItemType =  new CreditsItemType;
				
				nameComp.stringValue = "Kamal";
				givenNameArray.push(nameComp);
				
				personName.givenNameArray = givenNameArray;
				personNameArray.push(personName);
				recipient.personNameArray = personNameArray;
				
				award.recipient = recipient;
				
				awardArray.push(award);
				awardListItem.awardArray = awardArray;
				
 				awardListItemArray.push(awardListItem);
 				awardsList.awardsListItemArray = awardListItemArray;
				basicContent.awardsList = awardsList;
				
				var parentalGuidance:ParentalGuidanceType = constructParentalGuidance("Parents Strongly Cautioned(PG-13)", "Parents Strongly Cautioned(PG-13)")
				parentalGuidanceArray.push(parentalGuidance);
				
				basicContent.parentalGuidanceArray = parentalGuidanceArray;
				
				programInfo.basicDescription = basicContent;
				programInfoArray.push(programInfo);
				
				programInfoTable.programInformationArray = programInfoArray;
				programDesc.programInformationTable = programInfoTable;
				tvaMain.programDescription = programDesc;
				tvaMain.publicationTime = "2006-09-15T00:00:00Z";
				
				tvaMainDoc.TVAMain = tvaMain;
				
				return tvaMainDoc;
		}
		
	   /**
	   * contructing CreditItemList based on Product's CreditListType Object.
	   * @param product - ProgramInformation Object.
	   * @return CreditsListType - contructed CreditListType Returned  
	   */
		public static function constructCreditItemList(product:Product):CreditsListType {
			
			var creditList:CreditsListType = null;
			var creditsItemListArray:ArrayCollection = product.creditorArray;
			
			if(creditsItemListArray != null && creditsItemListArray.length !=0) {

				creditList = new CreditsListType;
				var creditsItemArray:Array = new Array;
				for (var i:Number=0; i<creditsItemListArray.length ; i++) {
					
					var creditsValue:String = creditsItemListArray.getItemAt(i) as String;
					
					if(creditsValue !=null) {
						
						var creditValueArray:Array = creditsValue.split(":");
						
						if(creditValueArray.length >= 2) {
							
							var creditRole:String = creditValueArray[0];
							var creditName:String = creditValueArray[1];

							var creditItem:CreditsItemType = new CreditsItemType;
							creditItem.role = MetasoftULC.RoleCS + creditRole;
							var personNameArray:Array = new Array;
							var personName:PersonNameType = new PersonNameType;
							var givenNameArray:Array = new Array;
							
							var nameComp:NameComponentType = new NameComponentType;
							nameComp.stringValue = creditName;
							givenNameArray.push(nameComp);
							
							personName.givenNameArray = givenNameArray;
							personNameArray.push(personName);
							creditItem.personNameArray = personNameArray;
							
							creditsItemArray.push(creditItem);
						}
					}
				}
				creditList.creditsItemArray = creditsItemArray;
			}
			
			return creditList;
		}
		
	   /**
	   * contructing AwardsListType based on Product's CreditListType Object.
	   * @param product - ProgramInformation Object.
	   * @return AwardsListType - contructed AwardsListType Returned  
	   */
		public static function constructAwardList(product:Product):AwardsListType {
			
			var awardsList:AwardsListType = null;
			var awardItemListArray:ArrayCollection = product.awardListArray;
			
			if(awardItemListArray != null && awardItemListArray.length !=0) {

				awardsList = new AwardsListType;
				var awardListItemArray:Array = new Array;
				
				var awardListItem:AwardsListItemType = null;
	            var awardArray:Array;
	            var givenNameArray:Array;
	            var awardType:TextualType = null;
	            var nameComp:NameComponentType = null;
	            var personNameArray:Array;
				var personName:PersonNameType = null;
				var award:AwardType = null;
	            var recipient:CreditsItemType =  null;
				var givenNameArray:Array = new Array;
				for (var i:Number=0; i < awardItemListArray.length ; i++) {
					
					var awardsValue:String = awardItemListArray.getItemAt(i) as String;
					
					if(awardsValue !=null) {
						
						var awardValueArray:Array = awardsValue.split(":");
						if(awardValueArray.length >= 2) {
							
							awardListItem = new AwardsListItemType;
			            	awardArray = new Array;
			            	givenNameArray = new Array;
			            	awardType = new TextualType;
			            	nameComp = new NameComponentType;
			            	personNameArray = new Array;
							personName = new PersonNameType;
							givenNameArray = new Array;
						
							var title:String = awardValueArray[0];
							var receiver:String = awardValueArray[1];

				            awardType.stringValue = title;
				            awardListItem.title = awardType;
				            
				            award = new AwardType;
				            recipient =  new CreditsItemType;
				            
				            nameComp.stringValue = receiver;
				            givenNameArray.push(nameComp);
				            
				            personName.givenNameArray = givenNameArray;
				            personNameArray.push(personName);
				            recipient.personNameArray = personNameArray;
				            
				            award.recipient = recipient;
				            
				            awardArray.push(award);
				            awardListItem.awardArray = awardArray;
				            
				            awardListItemArray.push(awardListItem);
						}
					}
				}
				awardsList.awardsListItemArray = awardListItemArray;
			}
			
			return awardsList;
		}
		
		/**
		 * Convert Genre XML Object into Array
		 * @param pgInfo - XMLList
		 * @return converted array object 
		 */
		public static function getGenreFromObjectByProduct(genreArray:Array, typeGenre:String, product:Product):Array {

			if (genreArray == null) {
				return new Array();
			}
			var genre:Object;
			var pg:Array = new Array();
			for each(genre in genreArray) {

				if (genre == null) { 
					continue;
				}
				var href:String  = genre.href;
				if (href != null) {
					if (href.indexOf(typeGenre) != -1 && 
						genre.name != null){
							
						setProductGenreTypes(genre.name.stringValue, genre.href, typeGenre, product);
//						pg.push(genre.name.stringValue, genre.name.stringValue);
						pg[genre.name.stringValue] = genre.name.stringValue;
					}
				}
			}
			return pg;
		}
		
		private static function setProductGenreTypes(genreName:String, genreHref:String, genreType:String, product:Product):void {
			
			if(genreName != null && genreHref!=null && genreType !=null) {
				
				if(MetasoftULC.CS_Content == genreType) {
					
					product.genreName = genreName;
					product.genreHref = genreHref;
				} else if(MetasoftULC.CS_ContentType == genreType) {

					product.contentName = genreName;
					product.contentHref = genreHref;
				} else if(MetasoftULC.CS_Intention == genreType) {

					product.intendName = genreName;
					product.intendHref = genreHref;
				} else if(MetasoftULC.CS_OriginationType == genreType) {

					product.origiName = genreName;
					product.origiHref = genreHref;
				} else if(MetasoftULC.CS_Atmosphere == genreType) {

					product.atomesName = genreName;
					product.atomesHref = genreHref;
				} else if(MetasoftULC.CS_Format == genreType) {

					product.contentFormatName = genreName;
					product.contentFormatHref = genreHref;
				} else if(MetasoftULC.CS_IntendedAudience == genreType) {
 
					product.intendAudName = genreName;
					product.intendAudHref = genreHref;
				} else if(MetasoftULC.CS_ContentAlertType == genreType) {
 
					product.contentAlertName = genreName;
					product.contentAlertHref = genreHref;
				} 
				
			}
		}
		
		public static function getUserImagePath():String {
			
			var userImagePath:String = "";
	   	  	var so:SharedObject = SharedObject.getLocal(MetasoftULC.LoggedInUser);
			var userId:String = so.data.userId;
			if(userId !=null)
				userImagePath = MetasoftULC.UserImgDir+ userId;
				
			return userImagePath;
		}
		
		public static function sortOnMemberOfIndex(a:Product, b:Product):Number {
			
    		var aIndex:Number = a.memberOfIndex;
    		var bIndex:Number = b.memberOfIndex;

    		if(aIndex > bIndex) {
        		return 1;
    		} else if(aIndex < bIndex) {
        		return -1;
    		} else  {
        		return 0;
		    }
		}
		
		private static function getMemeberOfIndex(memberOfArray:Array, groupId:String) :Number {

			var indexValue:Number = 0;			
			if(groupId !=null && groupId!="" &&	
				memberOfArray != null && memberOfArray.length > 0) {

				var memberOf:Object = new Object;
				for each(memberOf in memberOfArray) {
					
					if(memberOf !=null && memberOf.crid !=null && memberOf.crid !="") {
						
						if(groupId == memberOf.crid) {
							
							indexValue = memberOf.index;
							break;
						}
					}
				}
			}
			
			return indexValue;
		}
		
		/**
		 * Clear the whitespace in GroupID
		 */
		public static function replaceEmptyString(resultString:String) :String {
			
		 var resultStr:String="";
		 var resultArray:Array = resultString.split(" ");
			
			for (var i : int = 0; i < resultArray.length ; i ++) {
				resultStr = resultStr.concat(resultArray[i].toString());
			}
			return resultStr;
		}
		
		/**
		 * Clears Shared Object details of the logged-in user
		 * onSign-off
		 * */
		public static function clearSharedObjectDetails() : void
		{
			var so:SharedObject = SharedObject.getLocal(MetasoftULC.LoggedInUser);
			if (so != null && so.data != null)
			{
//				var userName : String = so.data.userId;
//				var password : String = so.data.password;
//				so.clear();
//				so.data.userId = userName;
//				so.data.password = password;
				so.data.preference = null;
				so.data.profileInfo = null;
				so.data.assets = null;
				so.data.groupArray = null;
				so.data.serviceInfoArray = null;
				so.data.seletedGroup=null;
				so.data.seletedProgramInfo=null;
				so.data.thumbnail = null;
				so.data.preview=null;
				so.data.resource=null;
				so.data.targets = null;
			} 
		}

		private static function getTitleArray(title:String) :Array {
			
			var titleArray:Array = null;
			if(title !=null && title.length !=0) {
					
				var titleType:TitleType = new TitleType;
				titleType.lang = title;
				titleType.stringValue = title;
				titleArray = new Array;
				titleArray.push(titleType);
			}
			
			return titleArray;
		}
		
		private static function getSynopsisArray(synopsis:String) :Array {
			
			var synopsisArray:Array = null;
			if(synopsis !=null && synopsis.length !=0) {
			
				var synopsisType:SynopsisType = new SynopsisType;
				var synopsisLength:SynopsisLengthType = new SynopsisLengthType;
				synopsisType.stringValue = synopsis;
				synopsisLength.length = "short";
				synopsisType.length = synopsisLength;
				synopsisArray = new Array;
				synopsisArray.push(synopsisType);
			}
			
			return synopsisArray;
		}
		
		private static function getSegmentLocator(incTimePoint:String, incDuration:String) :TVAMediaTimeType {
			
			var segmentLocator:TVAMediaTimeType = null;
			if(incTimePoint !=null) {
				
				var segmentLocator:TVAMediaTimeType = new TVAMediaTimeType;
				var mediaTimeUnit:String = "PT1N25F";
				
				if(incTimePoint !=null && incTimePoint!="") {
					
					var mediaRelIncrTimePoint:TVAMediaRelIncrTimePointType = new TVAMediaRelIncrTimePointType;
					incTimePoint = "" + parseFloat(incTimePoint) * 1000;
					mediaRelIncrTimePoint.mediaTimeUnit = mediaTimeUnit;
					mediaRelIncrTimePoint.lang = incTimePoint;
					mediaRelIncrTimePoint.stringValue = incTimePoint;
					
					segmentLocator.mediaRelIncrTimePoint = mediaRelIncrTimePoint;
				}
				
				if(incDuration !=null && incDuration !="") {
					
					var mediaIncrDuration:MediaIncrDurationType = new MediaIncrDurationType;
					incDuration = "" + parseFloat(incDuration) * 1000;
					mediaIncrDuration.mediaTimeUnit = mediaTimeUnit;
					mediaIncrDuration.lang = incDuration;
					mediaIncrDuration.stringValue = incDuration;
					segmentLocator.mediaIncrDuration = mediaIncrDuration;
				}
				
			}
			
			return segmentLocator;
		}
		
		public static function getSegmentationInfo(get_Data_Result:Object):Array {

			var so:SharedObject = SharedObject.getLocal(MetasoftULC.LoggedInUser);
			var j:int = 0;
			var segmentItems:Array = new Array();
			var segmentItem:SegmentItem;
			if (get_Data_Result == null) return segmentItems;
			var tvaMain:Object = get_Data_Result.TVAMain;
            if (tvaMain == null) return segmentItems;
            var programDescription:Object = tvaMain.programDescription;
            if (programDescription == null) return segmentItems;
            var segmentInformationTable:Object = programDescription.segmentInformationTable;
            if (segmentInformationTable != null) {
        		segmentItem = new SegmentItem;
            } else {
            	return segmentItems;
            }
            
            var segmentList:Object = segmentInformationTable.segmentList;
            if(segmentList !=null) {

	            var segmentInformationArray:Array = segmentList.segmentInformationArray;
				if (segmentInformationArray != null && segmentInformationArray.length > 0) {
					
					var segmentInfoArray:Array = new Array;
		            var segmentInfo:Object = new Object;
		            //var segmentInfo:SegmentInformationType = new SegmentInformationType;
		            for each(segmentInfo in segmentInformationArray) {
		            	
		            	var segmentInfoDTO:SegmentInfoDTO = new SegmentInfoDTO;
						if (segmentInfo != null && segmentInfo.programRef != null){
							
							segmentInfoDTO.programRef = segmentInfo.programRef.crid;
						}
						
						if (segmentInfo != null && segmentInfo.segmentId != null) {
							
							segmentInfoDTO.segmentId = segmentInfo.segmentId;
						}
						
						if (segmentInfo != null && segmentInfo.segmentLocator != null) {
							
							var segmentLocator:Object = segmentInfo.segmentLocator;
							
							var mediaRelIncrTimePoint:Object = segmentLocator.mediaRelIncrTimePoint;
							var mediaIncrDuration:Object = segmentLocator.mediaIncrDuration;
							
							if(mediaRelIncrTimePoint != null) {
								
								if(mediaRelIncrTimePoint.mediaTimeUnit != null)
									segmentInfoDTO.mediaRelIncrTimePoint =  mediaRelIncrTimePoint.mediaTimeUnit;
								
								if(mediaRelIncrTimePoint.stringValue != null)
									segmentInfoDTO.mediaRelIncrLangValue =  mediaRelIncrTimePoint.stringValue;
							}
							
							
							if(mediaIncrDuration !=null) {
								
								if(mediaIncrDuration.mediaTimeUnit != null)
									segmentInfoDTO.mediaIncrDuration =  mediaIncrDuration.mediaTimeUnit;
								
								if(mediaIncrDuration.stringValue != null)
									segmentInfoDTO.mediaIncrDurationLangValue =  mediaIncrDuration.stringValue;
								
							}
						}
						
						var description:Object = segmentInfo.description as Object;
						if (description != null) {
							
							if (description.titleArray[0] != null) {
								segmentInfoDTO.title = description.titleArray[0].stringValue;
							}
							
							if (description.synopsisArray[0] != null) {
								segmentInfoDTO.synopsis = description.synopsisArray[0].stringValue;
							}
							
							if (description.keywordArray != null &&
								description.keywordArray.length > 0) {
								
								segmentInfoDTO.keyword = description.keywordArray[0].stringValue;
							}
	
							if (description.genreArray != null && 
								description.genreArray.length > 0) {
		
								var genreArray:Array 	= description.genreArray;
						    }
	
							if (description.relatedMaterialArray != null && 
								description.relatedMaterialArray is Array && 
								description.relatedMaterialArray.length > 0) {
		
								//temp = description.relatedMaterialArray;
							}
							
							if (description.creditsList != null) {
								//prgItem.creditItems = getCreditItemsFromProxy(description.creditsList, prgItem);
							}
						}
						segmentInfoArray.push(segmentInfoDTO);
		            }
		            segmentItem.segmentInfoArray = segmentInfoArray;
	  			}
            }
            
            //segmentGroupList:SegmentGroupListType
            var segmentGroupList:Object = segmentInformationTable.segmentGroupList;
            if(segmentGroupList !=null) {
            	
            	var segmentGroupInformationArray:Array = segmentGroupList.segmentGroupInformationArray;
				if (segmentGroupInformationArray != null && segmentGroupInformationArray.length > 0) {

					var segmentGroupInfo:Object = new Object;
		            for each(segmentGroupInfo in segmentGroupInformationArray) {
						
						if(segmentGroupInfo.programRef != null)
							segmentItem.programRef =  segmentGroupInfo.programRef.crid;

						if(segmentGroupInfo.groupId != null)
							segmentItem.groupId =  segmentGroupInfo.groupId;
						
						var groupDescription:Object = segmentGroupInfo.description as Object;
						if (groupDescription == null) {
							continue;
						}
						
						if (groupDescription.titleArray[0] != null) {
							segmentItem.title = groupDescription.titleArray[0].stringValue;
						}
						
						if (groupDescription.synopsisArray[0] != null) {
							segmentItem.synopsis = groupDescription.synopsisArray[0].stringValue;
						}
						
						if (groupDescription.keywordArray != null &&
							groupDescription.keywordArray.length > 0) {
							
							segmentItem.keyword = groupDescription.keywordArray[0].stringValue;
						}

						if (groupDescription.genreArray != null && 
							groupDescription.genreArray.length > 0) {
	
							var genreArray:Array 	= groupDescription.genreArray;
					    }

						if (groupDescription.relatedMaterialArray != null && 
							groupDescription.relatedMaterialArray is Array && 
							groupDescription.relatedMaterialArray.length > 0) {
	
							//temp = description.relatedMaterialArray;
						}
						
						if (groupDescription.creditsList != null) {
							//prgItem.creditItems = getCreditItemsFromProxy(description.creditsList, prgItem);
						}
						
						var segments:Object = segmentGroupInfo.segments as Object;
						if (segments != null && segments.refList != null && segments.refList.length !=0) {
							
							var segmentsValue:String = "";
							for(j = 0; j < segments.refList.length; j++) {
	
								if (segments.refList[j] != null) {
									
									segmentsValue = segmentsValue + segments.refList[j] + " ";
								}
							}
							segmentItem.segments = segmentsValue;
						}

		            }
				}
            }
            segmentItems.push(segmentItem);
			return segmentItems;
		}
		
		public static function constructSegmentInfo(programId:String, product:Product):SegmentInformationTableType {
			
			var groupId:String = product.siGroupId;
			var groupTitle:String = product.siGroupTitle;
			var groupDesc:String = product.siGroupDesc;
			var segmentList:Array = product.segmentList;
			
			var segmentInfoTable:SegmentInformationTableType = new SegmentInformationTableType;
			var segmentInfoList:SegmentListType = getSegmentList(programId, segmentList);
			//var refList:Array = getSegmentRefList(segmentList);
			//var segmentGroupList:SegmentGroupListType = getSegmentInfoGroupList(programId, groupId, groupTitle, groupDesc, refList);
			
			segmentInfoTable.segmentList = segmentInfoList;
			//segmentInfoTable.segmentGroupList = segmentGroupList;
			
			//programDesc.segmentInformationTable = segmentInfoTable;
			return segmentInfoTable;
		}
		
		private static function getSegmentList(programId:String, segmentList:Array) : SegmentListType {
			
			var segmentInfoList:SegmentListType = new SegmentListType;
			
			var programRef:CRIDRefType = new CRIDRefType;
			programRef.crid = programId;
			
			var segmentInformationArray:Array = new Array;
			if(segmentList !=null && segmentList.length !=0) {
				
				for (var i:int = 0 ; i < segmentList.length; i++) {
					
					var segmentObject:Object = segmentList[i];
					if(segmentObject !=null) {
						
						//SegmentInformation
						var segmentInfo:SegmentInformationType = new SegmentInformationType;
						segmentInfo.programRef = programRef;
						segmentInfo.segmentId = segmentObject.name;
						
						//BasicSegmentDescriptionType
						if(segmentObject.title !=null && segmentObject.synopsis !=null) {
							
							var descriptionStatusFlag:Boolean = false;
							var description:BasicSegmentDescriptionType = new BasicSegmentDescriptionType;
							//Title
							if(segmentObject.title.length !=0) {
								var title:String = segmentObject.title;
								var titleArray:Array = getTitleArray(title);
								if(titleArray !=null && titleArray.length !=0) {
									description.titleArray = titleArray;
									descriptionStatusFlag = true;
								}
							}
							
							//Synopsis
							if(segmentObject.title.length !=0) {
								var synopsis:String = segmentObject.synopsis;
								var synopsisArray:Array = getSynopsisArray(synopsis);
								if(synopsisArray !=null && synopsisArray.length !=0) {
									description.synopsisArray = synopsisArray;
									descriptionStatusFlag = true;
								}
							}
							
							if(descriptionStatusFlag)
								segmentInfo.description = description;
						}
						
						//SegmentLocator
						var segmentLocator:TVAMediaTimeType = getSegmentLocator(segmentObject.time, segmentObject.duration);
						if(segmentLocator !=null) {

							segmentInfo.segmentLocator = segmentLocator;
							segmentInformationArray.push(segmentInfo);
						}
					}
				}
			}

			if(segmentInformationArray.length !=0) 
				segmentInfoList.segmentInformationArray = segmentInformationArray;

			return segmentInfoList;
		}
		
		private static function getSegmentInfoGroupList(programId:String, groupId:String, groupTitle:String, groupDesc:String, refList:Array) : SegmentGroupListType {
			
			var segmentGroupList:SegmentGroupListType = new SegmentGroupListType;
			var segmentGroupInformationArray:Array = new Array;
			
			var programRef:CRIDRefType = new CRIDRefType;
			programRef.crid = programId;
			
			//SegmentGroupInformationType
			var segmentGroupInfo: SegmentGroupInformationType = new SegmentGroupInformationType;
			segmentGroupInfo.programRef = programRef;
			if(groupId != null && groupId.length !=0)
				segmentGroupInfo.groupId = groupId;
			else
				segmentGroupInfo.groupId = programId + "/" + replaceEmptyString(groupTitle);
			
			 //BasicSegmentDescriptionType
				var description:BasicSegmentDescriptionType = new BasicSegmentDescriptionType;
				//Title
				var title:String = groupTitle;
				var titleArray:Array = getTitleArray(title);
				if(titleArray !=null && titleArray.length !=0)
					description.titleArray = titleArray;
				
				//Synopsis
				var synopsis:String = groupDesc;
				var synopsisArray:Array = getSynopsisArray(synopsis);
				if(synopsisArray !=null && synopsisArray.length !=0)
					description.synopsisArray = synopsisArray;
					
			segmentGroupInfo.description = description;
			
			//Segments
			if(refList !=null && refList.length !=0) {
				
				var segmentType:SegmentsType = new SegmentsType;
				segmentType.refList = refList;
				segmentGroupInfo.segments = segmentType;
			}
			segmentGroupInformationArray.push(segmentGroupInfo);
			segmentGroupList.segmentGroupInformationArray = segmentGroupInformationArray;
			
			return segmentGroupList;
		}
		
		private static function getSegmentRefList(segmentList:Array):Array {
			
			var refList:Array = new Array;
			if(segmentList !=null && segmentList.length !=0) {
				
				for (var i:int = 0 ; i < segmentList.length; i++) {
					var segmentObject:Object = segmentList[i];
					if(segmentObject !=null && segmentObject.name !=null) {
						
						refList.push(segmentObject.name);
					}
				}
			}
			
			return refList; 
		} 
		
		public static function clearTitleShareObjects():void {
			
			var so:SharedObject = SharedObject.getLocal(MetasoftULC.LoggedInUser);
			so.data.preview = null;
			so.data.resource = null;
			so.data.preview = null;
		}

		/**
		 * Method to save the targeting information
		 * 
		 * */
		public static function saveTargetingInformation(targetingInfo : TargetingInfoDTO) : TVAMainDocument
		{
			if (targetingInfo == null) return null;
			var tvaMainDoc : TVAMainDocument = new TVAMainDocument();
			var tvaMain : ExtendedTVAMainType  =  new ExtendedTVAMainType();
			var targetInfoTable : TargetingInformationTableType = new TargetingInformationTableType();
			var targetingInformation : TargetingInformationType = new TargetingInformationType();
			targetingInformation.targetingId = targetingInfo.targetID;
			var userPreferencesType : UserPreferencesType = new UserPreferencesType();
			var filteringAndSearchPreferences : FilteringAndSearchPreferencesType = new FilteringAndSearchPreferencesType();
			var creationPreferencesType : CreationPreferencesType = new CreationPreferencesType();
			var classificationPreferenceType : ClassificationPreferencesType = new ClassificationPreferencesType();
			 
			userPreferencesType.userIdentifier = new UserIdentifierType();
			userPreferencesType.userIdentifier.name = new TextualType();
			userPreferencesType.userIdentifier.name.stringValue = targetingInfo.targetName;
			
			if (targetingInfo.keywordDetailsArray != null){
				creationPreferencesType.keywordArray = new Array();
				for (var key:String in targetingInfo.keywordDetailsArray) {
					var keyPref:String = targetingInfo.keywordDetailsArray[key];
					var keyPrefNumValue:Number;
					if (keyPref is String){
						keyPrefNumValue = Number(keyPref);
						if(isNaN(keyPrefNumValue)) 
							keyPrefNumValue = MetasoftULC.default_PrefValue;
						if (keyPrefNumValue != 0 )
						{
							var keyWord : Keyword = new Keyword();
							keyWord.stringValue = key;
							keyWord.preferenceValue = keyPrefNumValue;
							creationPreferencesType.keywordArray.push(keyWord);
						}
					}
				}
			}
			
			if (targetingInfo.creditNamesDetailsArray != null)
			{
				creationPreferencesType.creatorArray = new Array();
				for (var creator:String in targetingInfo.creditNamesDetailsArray) {
					var creatorPref:String = targetingInfo.creditNamesDetailsArray[creator];
					var creatorPrefNumValue:Number;
					if (creatorPref is String){
						creatorPrefNumValue = Number(creatorPref);
						if(isNaN(creatorPrefNumValue)) 
							creatorPrefNumValue = MetasoftULC.default_PrefValue;
						if (creatorPrefNumValue != 0 )
						{
							var creatorType: Creator  = new Creator();
							creatorType.role = new ControlledTermUseType();
							creatorType.role.nameArray = new Array();
							var nameType : Name = new Name();
							nameType.stringValue = creator;
							creatorType.role.nameArray.push(nameType);
							creatorType.preferenceValue = creatorPrefNumValue;
							creationPreferencesType.creatorArray.push(creatorType);
						}
					}
				}
			}
			if (targetingInfo.contentArray != null)
			{
				classificationPreferenceType.genreArray = new Array();
				for (var genreName:String in targetingInfo.contentArray) 
				{
					var genrePref:String = targetingInfo.contentArray[genreName];
					var genrePrefNumValue:int;
					if (genrePref is String){
						genrePrefNumValue = int(genrePref);
						if(isNaN(genrePrefNumValue)) 
							genrePrefNumValue = MetasoftULC.default_PrefValue;
					}
					var genre : Genre  = createGenre(genrePrefNumValue,genreName,MetasoftULC.CS_Content);
					classificationPreferenceType.genreArray.push(genre);	
				}
			}
			var userInformationType:UserInformationType = new UserInformationType();
			var biographicInformationType:BiographicInformationType = new BiographicInformationType();
			var personNameType:PersonNameType = new PersonNameType();
			var gN:NameComponentType = new NameComponentType;
			gN.givenName = targetingInfo.userInfoName;
			gN.stringValue = targetingInfo.userInfoName;
			personNameType.givenNameArray = new Array();
			personNameType.givenNameArray.push(gN);
			biographicInformationType.nameArray = new Array();
			biographicInformationType.nameArray.push(personNameType);
			biographicInformationType.ageGroup = new AgeRangeType();
			biographicInformationType.ageGroup.min = targetingInfo.userInfoAgeMin;
			biographicInformationType.ageGroup.max = targetingInfo.userInfoAgeMax;
			biographicInformationType.gender = targetingInfo.userInfoGender;
			var languageType : LanguageType = new LanguageType();
			languageType.type = new Type();
			languageType.type.type = "mainSpoken";
			languageType.stringValue = targetingInfo.userInfoLanguage;
			biographicInformationType.languageArray = new Array();
			biographicInformationType.languageArray.push(languageType);
			userInformationType.biographicInformationArray = new Array();
			userInformationType.biographicInformationArray.push(biographicInformationType);
			targetingInformation.userInformationArray = new Array();
			targetingInformation.userInformationArray.push(userInformationType);
			filteringAndSearchPreferences.creationPreferencesArray = new Array();
			filteringAndSearchPreferences.creationPreferencesArray.push(creationPreferencesType);
			filteringAndSearchPreferences.classificationPreferencesArray = new Array();
			filteringAndSearchPreferences.classificationPreferencesArray.push(classificationPreferenceType);
			userPreferencesType.filteringAndSearchPreferencesArray = new Array();
			userPreferencesType.filteringAndSearchPreferencesArray.push(filteringAndSearchPreferences);
			targetingInformation.targetUserPreferencesArray = new Array();
			targetingInformation.targetUserPreferencesArray.push(userPreferencesType);
			targetInfoTable.targetingInformationArray = new Array();
			targetInfoTable.targetingInformationArray.push(targetingInformation);
			tvaMain.targetingInformationTable = targetInfoTable;
			tvaMainDoc.TVAMain = tvaMain;
			return tvaMainDoc;
		}
		
		public static function loadTargetInformationTable(targetTable:Object):Array {
		
			var targetArray : Array = new Array();
			var targetTableArray:Array = targetTable.targetingInformationArray;
			   
			for (var targetCount:int = 0;targetCount < targetTableArray.length;targetCount++) {
				var targetInfo : TargetingInfoDTO = null;
				
				var targetId:Object = targetTableArray[targetCount].targetingId;
				var userPreferenceArray:Array = targetTableArray[targetCount].targetUserPreferencesArray;
				if (userPreferenceArray == null) continue;
				for (var prefCount:int =0;prefCount < userPreferenceArray.length;prefCount++) {

					var objUserIdentifier:Object = userPreferenceArray[prefCount];
					
					var userIdentifier:Object = objUserIdentifier.userIdentifier;
					var userIdentifierName:Object = userIdentifier.name.lang;
					targetInfo = new TargetingInfoDTO(userIdentifierName as String,targetId as String);
					var filteringSearchArray:Array =  userPreferenceArray[prefCount].filteringAndSearchPreferencesArray;
					if (filteringSearchArray == null) continue;
					for (var filteringCount:int = 0;filteringCount < filteringSearchArray.length;filteringCount++) {

						var filteringPreferenceValue:Object = filteringSearchArray[filteringCount].preferenceValue;
						var creationPreferencesArray:Array = filteringSearchArray[filteringCount].creationPreferencesArray;
						if (creationPreferencesArray == null) continue;
						for (var creationCount:int = 0;creationCount < creationPreferencesArray.length;creationCount++) {

							var creationPreferenceValue:Object = creationPreferencesArray[creationCount].preferenceValue; 
							var creatorArray:Array = creationPreferencesArray[creationCount].creatorArray;
							if (creatorArray == null) continue;
							for (var creatorCount:int = 0;creatorCount < creatorArray.length;creatorCount++) {

								var creatorPreferenceValue:Object = creatorArray[creatorCount].preferenceValue;
								var role:Object = creatorArray[creatorCount].role;
								var nameArray:Array = role.nameArray;
								var name:Array = new Array();
								if (nameArray != null && nameArray.length > 0){
									targetInfo.creditNamesDetailsArray[nameArray[0].lang] = creatorArray[creatorCount].preferenceValue;
									targetInfo.creditNamesProvider.push(nameArray[0].lang);
								}
							}
							var keywordArray:Array = creationPreferencesArray[creationCount].keywordArray;
							if (keywordArray == null) continue;
							for (var keywordCount : int =0;keywordCount < keywordArray.length;keywordCount++) {
								targetInfo.keywordDetailsArray[keywordArray[keywordCount].stringValue] = keywordArray[keywordCount].preferenceValue;
								targetInfo.keywordProvider.push(keywordArray[keywordCount].stringValue);
							}
							break;  
						}
						
						var classificationPreferencesArray:Array = filteringSearchArray[filteringCount].classificationPreferencesArray;
						if (classificationPreferencesArray != null){
							for (var classificationCount:int = 0;classificationCount < classificationPreferencesArray.length; classificationCount ++) {
								var genreArray:Array = classificationPreferencesArray[classificationCount].genreArray;
								for (var genreCount:int = 0;genreCount < genreArray.length; genreCount++) {
									var genreObj : Object = genreArray[genreCount];
									if (genreObj ==  null) continue;
									var genreNameArray:Array = genreObj.nameArray;
									if (genreNameArray != null && genreNameArray.length > 0){
										if (String(genreObj.href).indexOf(MetasoftULC.CS_Content) != -1)
										{
											targetInfo.contentArray[genreNameArray[0].lang] = genreObj.preferenceValue;
										}else if (String(genreObj.href).indexOf(MetasoftULC.CS_Intention) != -1)
										{
											targetInfo.intentionArray[genreNameArray[0].lang] = genreObj.preferenceValue;
										}else if (String(genreObj.href).indexOf(MetasoftULC.CS_Atmosphere) != -1)
										{
											targetInfo.atmosphereArray[genreNameArray[0].lang] = genreObj.preferenceValue;
										}else if (String(genreObj.href).indexOf(MetasoftULC.CS_IntendedAudience) != -1)
										{
											targetInfo.audienceArray[genreNameArray[0].lang] = genreObj.preferenceValue;
										}
									}
								 }
							}
						}	
					}				
					 
				}
				var userInfomationArray : Array = targetTableArray[targetCount].userInformationArray;
				if ( userInfomationArray != null && userInfomationArray.length > 0)
				{
					var userInfoObject : Object = userInfomationArray[0];
					var biographicInformationArray : Array = userInfoObject.biographicInformationArray;
					if (biographicInformationArray != null && biographicInformationArray.length > 0){
						var biographicInformationObj : Object = biographicInformationArray[0];
						if (biographicInformationObj != null)
						{
							if (biographicInformationObj.ageGroup != null ){
								if (biographicInformationObj.ageGroup.min != null)
									targetInfo.userInfoAgeMin = Number(biographicInformationObj.ageGroup.min);
								if (biographicInformationObj.ageGroup.max != null)
									targetInfo.userInfoAgeMax = Number(biographicInformationObj.ageGroup.max);
							}
							
							if (biographicInformationObj.nameArray != null && biographicInformationObj.nameArray.length > 0){
								var nameObj : Object = biographicInformationObj.nameArray[0];
								if (nameObj != null && nameObj.givenNameArray != null && nameObj.givenNameArray.length > 0){
									var givenNameObj : Object = nameObj.givenNameArray[0];
									if (givenNameObj != null)
										targetInfo.userInfoName = String(givenNameObj.stringValue);
								}
							} 
							if (biographicInformationObj.languageArray != null && biographicInformationObj.languageArray.length > 0){
								var languageObj : Object = biographicInformationObj.languageArray[0];
								if (languageObj != null)
									targetInfo.userInfoLanguage = languageObj.stringValue;
							}
							if (biographicInformationObj.stringValue  != null &&
								biographicInformationObj.stringValue.match(MetasoftULC.Gender_Female)) {
				        		targetInfo.userInfoGender = MetasoftULC.Gender_Female;
							} else {
								targetInfo.userInfoGender = MetasoftULC.default_Gender;
							}
						}
					}
				}
				targetArray.push(targetInfo);	 					
			}		
			return targetArray;
			
		}

	public static function isTitleExist(title:String, picatalog:ArrayCollection):Boolean {
			
			var result:Boolean = false;
			if(picatalog !=null && picatalog.length !=0) {
				
				var piObject:Object = new Object();
				var count:Number = 1;
				for each(piObject in picatalog) {
					
					if(piObject !=null && piObject.title !=null && title == piObject.title) {
						
						return true;
						break;
					}
				}
			}
			
			return result;
		}
		
		/**
	 	 * Constructing programId.
	 	 */
		public static function constructProgramId(title:String):String {
			
			var programId:String = null;
		
			if(title!=null)
				programId = MetasoftULC.CRID_NAME + replaceEmptyString(title) ;
			
			return programId;
		}
		
		public static function convertSegmentArrayToCuePointArray(segmentInfoArray:Array):Array {
			
			var cuePointArray:Array = new Array;
			var segmentInfo:Object = new Object;
            for each(segmentInfo in segmentInfoArray) {

				if (segmentInfo != null && segmentInfo != null) {
					
					var cpName:String = segmentInfo.segmentId;
					var cpTime:String = segmentInfo.mediaRelIncrLangValue;
					var cpDuration:String = segmentInfo.mediaIncrDurationLangValue;
					var cpTitle:String = segmentInfo.title;
        			var cpSynopsis:String = segmentInfo.synopsis;
					
					if(cpTime !=null && cpTime !="")
						cpTime = "" + (parseFloat(cpTime) / 1000);
						
					if(cpDuration !=null && cpDuration !="")
						cpDuration = "" + (parseFloat(cpDuration) / 1000);

					cuePointArray.push({name:cpName, time:cpTime, duration:cpDuration, title:cpTitle, synopsis:cpSynopsis, keyword:""});
				}
            }
            
            return cuePointArray;
		}
	}
}